1 /* Copyright (c) 2014-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef SIMGRID_MC_CHUNKED_DATA_HPP
8 #define SIMGRID_MC_CHUNKED_DATA_HPP
16 #include "src/mc/mc_forward.hpp"
17 #include "src/mc/PageStore.hpp"
22 /** A byte-string represented as a sequence of chunks from a PageStore
24 * In order to save memory when taking memory snapshots, a given byte-string
25 * is split in fixed-size chunks. Identical chunks (either from the same
26 * snapshot or more probably from different snpashots) share the same memory
29 * Thus a chunked is represented as a sequence of indices of each chunk.
32 /** This is where we store the chunks */
33 PageStore* store_ = nullptr;
34 /** Indices of the chunks in the `PageStore` */
35 std::vector<std::size_t> pagenos_;
41 for (std::size_t pageno : pagenos_)
42 store_->unref_page(pageno);
51 ChunkedData(ChunkedData const& that)
54 pagenos_ = that.pagenos_;
55 for (std::size_t pageno : pagenos_)
56 store_->ref_page(pageno);
58 ChunkedData(ChunkedData&& that)
61 that.store_ = nullptr;
62 pagenos_ = std::move(that.pagenos_);
63 that.pagenos_.clear();
65 ChunkedData& operator=(ChunkedData const& that)
69 pagenos_ = that.pagenos_;
70 for (std::size_t pageno : pagenos_)
71 store_->ref_page(pageno);
74 ChunkedData& operator=(ChunkedData && that)
78 that.store_ = nullptr;
79 pagenos_ = std::move(that.pagenos_);
80 that.pagenos_.clear();
84 /** How many pages are used */
85 std::size_t page_count() const { return pagenos_.size(); }
87 /** Get a chunk index */
88 std::size_t pageno(std::size_t i) const { return pagenos_[i]; }
90 /** Get a view of the chunk indices */
91 const std::size_t* pagenos() const { return pagenos_.data(); }
93 /** Get a a pointer to a chunk */
94 const void* page(std::size_t i) const
96 return store_->get_page(pagenos_[i]);
99 ChunkedData(PageStore& store, AddressSpace& as,
100 RemotePtr<void> addr, std::size_t page_count);