ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::system::MappedFile Class Reference

Description:

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.

Backend options:

  • mmap-mapping where supported.
  • Portable "read-all" into an internal buffer (always available, i.e on WindowsOS).

Definition at line 17 of file mappedfile.hpp.

#include <mappedfile.hpp>

Collaboration diagram for alib::system::MappedFile:
[legend]

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)
MappedFileoperator= (const MappedFile &)=delete
 Deleted copy assignment operator.
MappedFileoperator= (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.

Field Details:

◆ noMMapBuf

std::vector<std::max_align_t> alib::system::MappedFile::noMMapBuf
protected

Internal buffer used for fallback read mode.

Definition at line 103 of file mappedfile.hpp.

◆ size

std::size_t alib::system::MappedFile::size = 0
protected

Size of the loaded data.

Definition at line 102 of file mappedfile.hpp.

Constructor(s) / Destructor Details:

◆ ~MappedFile()

alib::system::MappedFile::~MappedFile ( )
inline

Destructor. Calls Close.

Definition at line 117 of file mappedfile.hpp.

Here is the call graph for this function:

Method Details:

◆ Close()

void alib::system::MappedFile::Close ( )
noexcept

Release resources (unmap / free buffer).

Definition at line 123 of file mappedfile.cpp.

Here is the call graph for this function:

◆ GetData()

template<typename T>
Data< T > alib::system::MappedFile::GetData ( ) const
inlinenoexcept

Returns a data-cursor for sequential read operations of the buffer.

Template Parameters
TThe data type to sequentially load from this cursor.
Returns
The data-cursor.

Definition at line 150 of file mappedfile.hpp.

◆ IsEmpty()

bool alib::system::MappedFile::IsEmpty ( ) const
inlinenoexcept
Returns
true if the view is empty.

Definition at line 164 of file mappedfile.hpp.

◆ IsMMap()

bool alib::system::MappedFile::IsMMap ( ) const
inlinenoexcept
Returns
true if the file was read with mmap mode, false otherwise.

Definition at line 138 of file mappedfile.hpp.

Here is the call graph for this function:

◆ Open()

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).

Parameters
pathThe file's path.
knownSizeFile size in bytes if known. Defaults to max() , which triggers size detection.
disableMMapIf true, skips mmap mode and uses standard read methods. Defaults to false.
willNeedIf true (the default), MADV_WILLNEED is passed to the function madvise. Otherwise MADV_SEQUENTIAL is passed.
Exceptions
std::runtime_erroron failure to open/read/map the file.
Returns
The error code of the operation.

Definition at line 9 of file mappedfile.cpp.

Here is the call graph for this function:

◆ operator=()

MappedFile & alib::system::MappedFile::operator= ( MappedFile && )
delete

Deleted assignment operator.

Returns
Void (deleted).
Here is the call graph for this function:

◆ Size()

std::size_t alib::system::MappedFile::Size ( ) const
inlinenoexcept
Returns
File size in bytes.

Definition at line 161 of file mappedfile.hpp.


The documentation for this class was generated from the following files: