move copy constructor for json_data

Đang mở
#979 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

@mitzimorris đang làm issue này rồi.

Từ ngày 4/7/2019.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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

Ngôn ngữ chính
C++
Star
240
Fork
105
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của stan-dev/cmdstan

Tất cả issue của stan-dev/cmdstan

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.