XII Release 0.1.0
Loading...
Searching...
No Matches
xiiMemoryMappedFile Class Reference

Allows to map an entire file into memory for random access. More...

#include <MemoryMappedFile.h>

Public Types

enum class  Mode { None , ReadOnly , ReadWrite }
 
enum class  OffsetBase { Start , End }
 The start point for interpreting byte offsets into the memory. More...
 

Public Member Functions

xiiResult Open (xiiStringView sAbsolutePath, Mode mode)
 Attempts to open the given file and map it into memory.
 
xiiResult OpenShared (xiiStringView sSharedName, xiiUInt64 uiSize, Mode mode)
 Attempts to open or create the given shared memory block addressed by szSharedName.
 
void Close ()
 Removes the memory mapping. Outstanding modifications will be written back to disk at this point.
 
Mode GetMode () const
 Returns the mode with which the file was opened or None, if is currently not in use.
 
xiiUInt64 GetFileSize () const
 Returns the size (in bytes) of the memory mapping. Zero if no file is mapped at the moment.
 
const void * GetReadPointer (xiiUInt64 uiOffset=0, OffsetBase base=OffsetBase::Start) const
 Returns a pointer for reading the mapped file. Asserts that the memory mapping was done successfully.
 
void * GetWritePointer (xiiUInt64 uiOffset=0, OffsetBase base=OffsetBase::Start)
 Returns a pointer for writing the mapped file. Asserts that the memory mapping was successful and the mode was ReadWrite.
 

Detailed Description

Allows to map an entire file into memory for random access.

Member Enumeration Documentation

◆ Mode

enum class xiiMemoryMappedFile::Mode
strong
Enumerator
None 

Currently no file is mapped.

ReadOnly 

File is mapped for read-only access.

ReadWrite 

File is mapped for read/write access.

◆ OffsetBase

The start point for interpreting byte offsets into the memory.

Enumerator
Start 

Byte offsets are relative to the start of the mapped memory.

End 

Byte offsets are relative to the end of the mapped memory. Increasing positive values go towards the start of the memory.

Member Function Documentation

◆ Open()

xiiResult xiiMemoryMappedFile::Open ( xiiStringView sAbsolutePath,
Mode mode )

Attempts to open the given file and map it into memory.

Parameters
szAbsolutePathmust be an absolute path to the file that should be mapped. The file also must exist and have a size larger than zero bytes.
modeHow to map the file into memory.

◆ OpenShared()

xiiResult xiiMemoryMappedFile::OpenShared ( xiiStringView sSharedName,
xiiUInt64 uiSize,
Mode mode )

Attempts to open or create the given shared memory block addressed by szSharedName.

Parameters
szSharedNameThe name of the shared memory region.
uiSizeThe size of the memory which should be mapped.
modeHow to map the file into memory.

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