File-to-memory loader with optional mmap backend. This class loads a file into memory and provides a stable pointer + length, which is only allowed to be read sequentially.
Definition at line 17 of file mappedfile.hpp.
#include <mappedfile.hpp>
Inner Type Index: | |
| class | Data |
Public Method Index: | |
| MappedFile ()=default | |
| Default constructor. Creates an empty view. | |
| MappedFile (const MappedFile &)=delete | |
| Deleted copy constructor. | |
| MappedFile (MappedFile &&)=delete | |
| Deleted move constructor. | |
| ~MappedFile () | |
| Destructor. Calls Close. | |
| void | Close () noexcept |
| Release resources (unmap / free buffer). | |
| template<typename T> | |
| Data< T > | GetData () const noexcept |
| bool | IsEmpty () const noexcept |
| bool | IsMMap () const noexcept |
| std::errc | Open (const CPathString &path, std::size_t knownSize=(std::numeric_limits< std::size_t >::max)(), bool disableMMap=false, bool willNeed=true) |
| MappedFile & | operator= (const MappedFile &)=delete |
| Deleted copy assignment operator. | |
| MappedFile & | operator= (MappedFile &&)=delete |
| std::size_t | Size () const noexcept |
Protected Field Index: | |
| std::vector< std::max_align_t > | noMMapBuf |
| Internal buffer used for fallback read mode. | |
| std::size_t | size = 0 |
| Size of the loaded data. | |
|
protected |
Internal buffer used for fallback read mode.
Definition at line 103 of file mappedfile.hpp.
|
protected |
Size of the loaded data.
Definition at line 102 of file mappedfile.hpp.
|
inline |
Destructor. Calls Close.
Definition at line 117 of file mappedfile.hpp.
|
noexcept |
Release resources (unmap / free buffer).
Definition at line 123 of file mappedfile.cpp.
|
inlinenoexcept |
Returns a data-cursor for sequential read operations of the buffer.
| T | The data type to sequentially load from this cursor. |
Definition at line 150 of file mappedfile.hpp.
|
inlinenoexcept |
true if the view is empty. Definition at line 164 of file mappedfile.hpp.
|
inlinenoexcept |
true if the file was read with mmap mode, false otherwise. Definition at line 138 of file mappedfile.hpp.
| std::errc alib::system::MappedFile::Open | ( | const CPathString & | path, |
| std::size_t | knownSize = (std::numeric_limits<std::size_t>::max)(), | ||
| bool | disableMMap = false, | ||
| bool | willNeed = true ) |
Load a file (replaces previous contents).
| path | The file's path. |
| knownSize | File size in bytes if known. Defaults to max() , which triggers size detection. |
| disableMMap | If true, skips mmap mode and uses standard read methods. Defaults to false. |
| willNeed | If true (the default), MADV_WILLNEED is passed to the function madvise. Otherwise MADV_SEQUENTIAL is passed. |
| std::runtime_error | on failure to open/read/map the file. |
Definition at line 9 of file mappedfile.cpp.
|
delete |
Deleted assignment operator.
|
inlinenoexcept |
Definition at line 161 of file mappedfile.hpp.