stan-dev / stan-dev/cmdstan

move copy constructor for json_data

Open
#979 1 comment 0 reactions 1 assignee View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.