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_;
38 ChunkedData() = default;
41 for (std::size_t pageno : pagenos_)
42 store_->unref_page(pageno);
51 ChunkedData(ChunkedData const& that)
52 : store_ (that.store_)
53 , pagenos_(that.pagenos_)
56 for (std::size_t pageno : pagenos_)
57 store_->ref_page(pageno);
59 ChunkedData(ChunkedData&& that)
62 that.store_ = nullptr;
63 pagenos_ = std::move(that.pagenos_);
64 that.pagenos_.clear();
66 ChunkedData& operator=(ChunkedData const& that)
70 pagenos_ = that.pagenos_;
71 for (std::size_t pageno : pagenos_)
72 store_->ref_page(pageno);
75 ChunkedData& operator=(ChunkedData && that)
79 that.store_ = nullptr;
80 pagenos_ = std::move(that.pagenos_);
81 that.pagenos_.clear();
85 /** How many pages are used */
86 std::size_t page_count() const { return pagenos_.size(); }
88 /** Get a chunk index */
89 std::size_t pageno(std::size_t i) const { return pagenos_[i]; }
91 /** Get a view of the chunk indices */
92 const std::size_t* pagenos() const { return pagenos_.data(); }
94 /** Get a a pointer to a chunk */
95 const void* page(std::size_t i) const
97 return store_->get_page(pagenos_[i]);
100 ChunkedData(PageStore& store, AddressSpace& as,
101 RemotePtr<void> addr, std::size_t page_count);