X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/9ae3c710a6a8ac04570f77d88eb8e0c7a13f101c..4b0aa1525597fd0800c4d00c6df3f3c49d53ee2c:/src/mc/sosp/ChunkedData.hpp diff --git a/src/mc/sosp/ChunkedData.hpp b/src/mc/sosp/ChunkedData.hpp new file mode 100644 index 0000000000..c904a29f97 --- /dev/null +++ b/src/mc/sosp/ChunkedData.hpp @@ -0,0 +1,94 @@ +/* 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. */ + +#ifndef SIMGRID_MC_CHUNKED_DATA_HPP +#define SIMGRID_MC_CHUNKED_DATA_HPP + +#include +#include + +#include +#include + +#include "src/mc/mc_forward.hpp" +#include "src/mc/sosp/PageStore.hpp" + +namespace simgrid { +namespace mc { + +/** 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 in the `PageStore` */ + std::vector pagenos_; + +public: + ChunkedData() = default; + void clear() + { + for (std::size_t const& pageno : pagenos_) + store_->unref_page(pageno); + pagenos_.clear(); + } + ~ChunkedData() { clear(); } + + // Copy and move + ChunkedData(ChunkedData const& that) : store_(that.store_), pagenos_(that.pagenos_) + { + for (std::size_t const& pageno : pagenos_) + store_->ref_page(pageno); + } + ChunkedData(ChunkedData&& that) : store_(that.store_), pagenos_(std::move(that.pagenos_)) + { + that.store_ = nullptr; + that.pagenos_.clear(); + } + ChunkedData& operator=(ChunkedData const& that) + { + this->clear(); + store_ = that.store_; + pagenos_ = that.pagenos_; + for (std::size_t const& pageno : pagenos_) + store_->ref_page(pageno); + return *this; + } + ChunkedData& operator=(ChunkedData&& that) + { + this->clear(); + store_ = that.store_; + that.store_ = nullptr; + pagenos_ = std::move(that.pagenos_); + that.pagenos_.clear(); + 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, RemotePtr addr, std::size_t page_count); +}; + +} // namespace mc +} // namespace simgrid + +#endif