X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/301989b17111d6a39df60385a4c2e73fcff8cd86..ff420e1906d916322427488153e45bf82d5c03dd:/src/mc/ChunkedData.hpp diff --git a/src/mc/ChunkedData.hpp b/src/mc/ChunkedData.hpp index 20711dff26..52b56c9a55 100644 --- a/src/mc/ChunkedData.hpp +++ b/src/mc/ChunkedData.hpp @@ -1,5 +1,4 @@ -/* Copyright (c) 2014-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2014-2018. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -14,23 +13,31 @@ #include #include "src/mc/mc_forward.hpp" -#include "src/mc/AddressSpace.hpp" #include "src/mc/PageStore.hpp" namespace simgrid { namespace mc { -/** A byte-string represented as a sequence of chunks from a PageStor */ +/** A byte-string represented as a sequence of chunks from a PageStore + * + * In order to save memory when taking memory snapshots, a given byte-string + * is split in fixed-size chunks. Identical chunks (either from the same + * snapshot or more probably from different snpashots) share the same memory + * storage. + * + * Thus a chunked is represented as a sequence of indices of each chunk. + */ class ChunkedData { + /** This is where we store the chunks */ PageStore* store_ = nullptr; - /** Indices of the chunks */ + /** Indices of the chunks in the `PageStore` */ std::vector pagenos_; public: - ChunkedData() {} + ChunkedData() = default; void clear() { - for (std::size_t pageno : pagenos_) + for (std::size_t const& pageno : pagenos_) store_->unref_page(pageno); pagenos_.clear(); } @@ -41,17 +48,17 @@ public: // Copy and move ChunkedData(ChunkedData const& that) + : store_ (that.store_) + , pagenos_(that.pagenos_) { - store_ = that.store_; - pagenos_ = that.pagenos_; - for (std::size_t pageno : pagenos_) + for (std::size_t const& pageno : pagenos_) store_->ref_page(pageno); } ChunkedData(ChunkedData&& that) + : store_(that.store_) + , pagenos_(std::move(that.pagenos_)) { - store_ = that.store_; that.store_ = nullptr; - pagenos_ = std::move(that.pagenos_); that.pagenos_.clear(); } ChunkedData& operator=(ChunkedData const& that) @@ -59,7 +66,7 @@ public: this->clear(); store_ = that.store_; pagenos_ = that.pagenos_; - for (std::size_t pageno : pagenos_) + for (std::size_t const& pageno : pagenos_) store_->ref_page(pageno); return *this; } @@ -73,18 +80,23 @@ public: return *this; } + /** How many pages are used */ std::size_t page_count() const { return pagenos_.size(); } + + /** Get a chunk index */ std::size_t pageno(std::size_t i) const { return pagenos_[i]; } + + /** Get a view of the chunk indices */ const std::size_t* pagenos() const { return pagenos_.data(); } + /** Get a a pointer to a chunk */ const void* page(std::size_t i) const { return store_->get_page(pagenos_[i]); } ChunkedData(PageStore& store, AddressSpace& as, - remote_ptr addr, std::size_t page_count, - const std::size_t* ref_page_numbers, const std::uint64_t* pagemap); + RemotePtr addr, std::size_t page_count); }; }