|
ADS
Algorithms and Data Structures
|
A file mapped in memory, shared by the structures that are read from it in place [see Persistence.h]: with ADS_WITH_BOOST, MappedFile maps a whole file by Boost.Interprocess in its mode copy_on_write (the private and writable mapping of every system), so that a page is read from the disk at its first access and a page that a structure writes is copied for the process and never reaches the file; without Boost, the file is read whole into a block aligned to a page, on which the views are made in the same way. More...
#include "ADS/Contract.h"#include <atomic>#include <cstddef>#include <cstdint>#include <filesystem>#include <initializer_list>#include <memory>#include <new>#include <span>#include <stdexcept>#include <string_view>#include <type_traits>#include <utility>#include "ADS/external/impl/MappedFile.tpp"Go to the source code of this file.
Classes | |
| class | ADS::PersistError |
| the error of a file (or a stream, or a buffer) of a structure that cannot be read: not a file of ADS, of another structure or version, truncated, corrupted, or refused by the system More... | |
| class | ADS::MappedFile |
| a whole file mapped privately in memory, shared by its copies More... | |
| class | ADS::MappableAllocator< T, V > |
| std::allocator, which also makes a vector over the bytes of a mapped file [see restoreMapped()]; an item constructed with no argument is value-initialized if \( V \), else left uninitialized (the numbers about to be written of a matrix) More... | |
| struct | ADS::MappableAllocator< T, V >::rebind< U > |
| the same allocator, of items of the type U More... | |
Namespaces | |
| namespace | ADS |
A file mapped in memory, shared by the structures that are read from it in place [see Persistence.h]: with ADS_WITH_BOOST, MappedFile maps a whole file by Boost.Interprocess in its mode copy_on_write (the private and writable mapping of every system), so that a page is read from the disk at its first access and a page that a structure writes is copied for the process and never reaches the file; without Boost, the file is read whole into a block aligned to a page, on which the views are made in the same way.
The copies of a MappedFile share the mapping, which is released with the last of them, as a std::shared_ptr does, but in a single pointer, since the allocators of the words of the succinct structures hold one [see BitVector.h].
An allocator that holds a mapping takes the bytes that the reader of a file offers it, offer(), at its next allocation of that size, take(), instead of new memory, constructs nothing over them, and gives back nothing that lies in the mapping, holds(): a vector is thus made over the bytes of the file in \( O( 1 ) \) time, with no copy. The offer is one at a time, made and taken by the thread that reads the file. MappableAllocator is such an allocator, which is std::allocator when it holds no mapping (the vectors of the filters and of the perfect hash functions are on it), and detail::LineAllocator of BitVector.h is another (the words of the succinct structures). A copy of a vector on them is made on new memory (select_on_container_copy_construction() holds no mapping), while a move and a swap take the mapping with the memory, so that each block goes back to the allocator that gave it.
An error of the system (a file that cannot be opened, read or mapped) throws PersistError, a std::runtime_error whose message names the file. The functions are defined in MappedFile.tpp.