Doxygen XLinks
by
V: 2511R0
Website: doxygen
Loading...
Searching...
No Matches
dxl::MappedFile Class Reference

Description:

Todox: ai-generated. RAII file-to-memory loader with optional mmap backend.

This class loads a file into memory and provides a stable pointer + length.

Backend options:

  • Portable "read-all" into an internal buffer (always available).
  • Optional mmap mapping on non-Windows builds
Warning
Performance note: This class is designed for sequential processing of the returned data. For best results (especially with mmap + MADV_SEQUENTIAL), treat data() as a forward-only byte stream: read from begin to end without repeated random jumps backwards/forwards.

todos:

  • move to alib::files
  • change exceptions to ALib or don't throw even.
  • use with classes TextFile and TextFileLineReader. Those are using std::basic_istream<CharT,Traits>::getline and that's quite slow
  • add option to switch between MADV_SEQUENTIAL and MADV_WILLNEED

Definition at line 46 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 char *path, std::size_t knownSize=std::numeric_limits< std::size_t >::max(), bool preferMmap=true)
 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).
bool IsEmpty () const noexcept
bool IsMMap () const noexcept
Data Open (const char *path, std::size_t knownSize=std::numeric_limits< std::size_t >::max(), bool disableMMap=false)
MappedFileoperator= (const MappedFile &)=delete
 Deleted copy assignment operator.
MappedFileoperator= (MappedFile &&)=delete
std::size_t Size () const noexcept

Protected Field Index:

std::vector< std::byte > noMMapBuf
 Internal buffer used for fallback read mode.
std::size_t size = 0
 Size of the loaded data.

Field Details:

◆ noMMapBuf

std::vector<std::byte> dxl::MappedFile::noMMapBuf
protected

Internal buffer used for fallback read mode.

Definition at line 127 of file mappedfile.hpp.

◆ size

std::size_t dxl::MappedFile::size = 0
protected

Size of the loaded data.

Definition at line 126 of file mappedfile.hpp.

Constructor(s) / Destructor Details:

◆ MappedFile()

dxl::MappedFile::MappedFile ( const char * path,
std::size_t knownSize = std::numeric_limits<std::size_t>::max(),
bool preferMmap = true )
inline

Construct and load a file.

Parameters
pathFile path.
knownSizeFile size in bytes if known. Defaults to max(), which triggers size detection.
preferMmapIf true, tries mmap first (when supported), else uses ReadAll.
Exceptions
std::runtime_erroron failure to open/read/map the file.

Definition at line 143 of file mappedfile.hpp.

◆ ~MappedFile()

dxl::MappedFile::~MappedFile ( )
inline

Destructor. Calls Close.

Definition at line 152 of file mappedfile.hpp.

Method Details:

◆ Close()

void dxl::MappedFile::Close ( )
noexcept

Release resources (unmap / free buffer).

Definition at line 110 of file mappedfile.cpp.

◆ IsEmpty()

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

Definition at line 176 of file mappedfile.hpp.

◆ IsMMap()

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

Definition at line 170 of file mappedfile.hpp.

◆ Open()

MappedFile::Data dxl::MappedFile::Open ( const char * path,
std::size_t knownSize = std::numeric_limits<std::size_t>::max(),
bool disableMMap = false )

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.
Exceptions
std::runtime_erroron failure to open/read/map the file.
Returns
A Data object.

Definition at line 22 of file mappedfile.cpp.

◆ operator=()

MappedFile & dxl::MappedFile::operator= ( MappedFile && )
delete

Deleted assignment operator.

Returns
Void (deleted).

◆ Size()

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

Definition at line 173 of file mappedfile.hpp.


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