MMAP Reader#

class MmapReader#

Memory-mapped file reader.

Provides efficient file reading using memory mapping (mmap). The file contents are mapped directly into memory without copying.

Public Types

enum class Mode#

Values:

enumerator kReadOnly#

Read-only shared file mapping.

enumerator kCopyOnWrite#

Writable copy-on-write mapping; writes cannot modify the file.

Public Functions

MmapReader() noexcept#

Default constructor.

explicit MmapReader(
std::filesystem::path const &fp,
Mode mode = Mode::kReadOnly
)#

Construct and load file.

Parameters:
  • fp – Path to file to load

  • mode – Mapping protection and sharing mode

Throws:

std::runtime_error – If file cannot be loaded

MmapReader(MmapReader const&) = delete#

Deleted copy constructor.

MmapReader &operator=(MmapReader const&) = delete#

Deleted copy assignment operator.

~MmapReader() noexcept#

Destructor.

void release() noexcept#

Release mapped memory.

bool loadFile(
std::filesystem::path const &fp,
Mode mode = Mode::kReadOnly
)#

Load and memory-map a file.

Parameters:
  • fp – Path to file to load

  • mode – Mapping protection and sharing mode

Returns:

True on success, false on failure

int8_t const *getByteData() const noexcept#

Get mapped data as byte array.

Returns:

Const pointer to byte data

void const *getData() const noexcept#

Get mapped data as void pointer.

Returns:

Const pointer to data

size_t getSize() const noexcept#

Get size of mapped data.

Returns:

Size in bytes