libcommonc++  0.7
MemoryMappedFile Class Reference

An abstraction of a memory-mapped file. More...

#include <MemoryMappedFile.h++>

Public Member Functions

 MemoryMappedFile (const String &path)
 Construct a new MemoryMappedFile for the given path. More...
 
 ~MemoryMappedFile ()
 Destructor. More...
 
void open (uint64_t size=0, bool readOnly=false)
 Open the file and map it into memory. More...
 
void close ()
 Unmap and close the file. More...
 
void sync (bool async=false)
 Synchronize the in-memory state of the file with the file on disk. More...
 
byte_tgetBase ()
 Get a pointer to the base of the mapped memory segment. More...
 
const byte_tgetBase () const
 Get a pointer to the base of the mapped memory segment. More...
 
uint64_t getSize () const
 Get the size of the memory mapped segment, in bytes. More...
 

Detailed Description

An abstraction of a memory-mapped file.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ MemoryMappedFile()

MemoryMappedFile ( const String path)

Construct a new MemoryMappedFile for the given path.

Parameters
pathThe path of the file to be mapped.

◆ ~MemoryMappedFile()

Destructor.

Unmaps the file.

Member Function Documentation

◆ close()

void close ( )

Unmap and close the file.

◆ getBase() [1/2]

byte_t* getBase ( )
inline

Get a pointer to the base of the mapped memory segment.

◆ getBase() [2/2]

const byte_t* getBase ( ) const
inline

Get a pointer to the base of the mapped memory segment.

◆ getSize()

uint64_t getSize ( ) const
inline

Get the size of the memory mapped segment, in bytes.

◆ open()

void open ( uint64_t  size = 0,
bool  readOnly = false 
)

Open the file and map it into memory.

Zero-length files cannot be mapped.

Parameters
sizeThe maximum file size to map; if the file being mapped is larger than this size, the file is truncated to the new size before it is mapped into memory. A value of 0 indicates that the maximum size is the current size of the file.
readOnlyA flag indicating whether the file should be mapped as read-only or read-write. If mapping read-only, the size parameter is ignored, and taken as 0.
Exceptions
IOExceptionIf the file to be mapped has a length of 0, or if the file could not be opened or the mapping operation failed.

◆ sync()

void sync ( bool  async = false)

Synchronize the in-memory state of the file with the file on disk.

Parameters
asyncA flag indicating whether the sync operation should occur asynchronously.
Exceptions
IOExceptionIf an I/O error occurs.

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