1 /* Copyright (c) 2014-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_MC_CHUNKED_DATA_HPP
7 #define SIMGRID_MC_CHUNKED_DATA_HPP
15 #include "src/mc/mc_forward.hpp"
16 #include "src/mc/sosp/PageStore.hpp"
21 /** A byte-string represented as a sequence of chunks from a PageStore
23 * In order to save memory when taking memory snapshots, a given byte-string
24 * is split in fixed-size chunks. Identical chunks (either from the same
25 * snapshot or more probably from different snpashots) share the same memory
28 * Thus a chunked is represented as a sequence of indices of each chunk.
31 /** This is where we store the chunks */
32 PageStore* store_ = nullptr;
33 /** Indices of the chunks in the `PageStore` */
34 std::vector<std::size_t> pagenos_;
37 ChunkedData() = default;
40 for (std::size_t const& pageno : pagenos_)
41 store_->unref_page(pageno);
44 ~ChunkedData() { clear(); }
47 ChunkedData(ChunkedData const& that) : store_(that.store_), pagenos_(that.pagenos_)
49 for (std::size_t const& pageno : pagenos_)
50 store_->ref_page(pageno);
52 ChunkedData(ChunkedData&& that) : store_(that.store_), pagenos_(std::move(that.pagenos_))
54 that.store_ = nullptr;
55 that.pagenos_.clear();
57 ChunkedData& operator=(ChunkedData const& that)
62 pagenos_ = that.pagenos_;
63 for (std::size_t const& pageno : pagenos_)
64 store_->ref_page(pageno);
68 ChunkedData& operator=(ChunkedData&& that)
72 that.store_ = nullptr;
73 pagenos_ = std::move(that.pagenos_);
74 that.pagenos_.clear();
78 /** How many pages are used */
79 std::size_t page_count() const { return pagenos_.size(); }
81 /** Get a chunk index */
82 std::size_t pageno(std::size_t i) const { return pagenos_[i]; }
84 /** Get a view of the chunk indices */
85 const std::size_t* pagenos() const { return pagenos_.data(); }
87 /** Get a a pointer to a chunk */
88 const void* page(std::size_t i) const { return store_->get_page(pagenos_[i]); }
90 ChunkedData(PageStore& store, AddressSpace& as, RemotePtr<void> addr, std::size_t page_count);
94 } // namespace simgrid