move copy constructor for json_data
@mitzimorris is already working on this.
Since Jul 4, 2019.
- Dominant language
- C++
- Stars
- 238
- Forks
- 106
- Avg merge
- 2h 29m
- Merged PRs (30d)
- 6
Description
Summary:
As json_data is being used in CmdStan, it does this:
stan::json::json_data d(stream);
stream.close();
std::shared_ptr<stan::io::var_context> result
= std::make_shared<stan::json::json_data>(d);
return result;
The class json_data is a subclass of var_context. It does not define a copy constructor, so the default copy constructor will be invoked by that call to make_shared (which constructs an object and returns a shared pointer to it that encapsulates the memory management). That means a deep copy of all the data. That means all the data sits in memory twice while this block is executing.
To solve this problem, we need to define move semantics so that the returned object constructed in the shared pointer can steal the data from the local object.
I'm not sure how to test this as we want to make sure we reduce total dynamic memory overhead requirements.
Current Version:
v2.19.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.