Plasma Engine  2.0
Loading...
Searching...
No Matches
plMemoryMappedFile 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

plResult Open (plStringView sAbsolutePath, Mode mode)
 Attempts to open the given file and map it into memory.
 
plResult OpenShared (plStringView sSharedName, plUInt64 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.
 
plUInt64 GetFileSize () const
 Returns the size (in bytes) of the memory mapping. Zero if no file is mapped at the moment.
 
const void * GetReadPointer (plUInt64 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 (plUInt64 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 plMemoryMappedFile::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

enum class plMemoryMappedFile::OffsetBase
strong

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

plResult plMemoryMappedFile::Open ( plStringView 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()

plResult plMemoryMappedFile::OpenShared ( plStringView sSharedName,
plUInt64 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: