class MappedFile

Map a named disk file into memory. More...

Full nameost::MappedFile
Definition#include <file.h>
Inheritsost::RandomFile [public ], ost::RandomFile [public ]
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods


Detailed Description

Create and map a disk file into memory. This portable class works under both Posix via mmap and under the win32 API. A mapped file can be referenced directly by it's memory segment. One can map and unmap portions of a file on demand, and update changed memory pages mapped from files immediately through sync().

 MappedFile (const char *fname, fileaccess_t mode)

MappedFile

Open a file for mapping. More than one segment of a file may be mapped into seperate regions of memory.

Parameters:
filename to access for mapping.
accessmode to map file.

 MappedFile (const char *fname, pos_t offset, size_t size, fileaccess_t mode)

MappedFile

Map a portion or all of a specified file in the specified shared memory access mode. Valid mapping modes include FILE_MAPPED_READ, FILE_MAPPED_WRITE, and FILE_MAPPED_RDWR.

Parameters:
fnamepathname of file to map into memory.
offsetfrom start of file to begin mapping in bytes.
sizeof mapped area in bytes.
modeto map file.

 ~MappedFile ()

~MappedFile

[virtual]

Release a mapped section of memory associated with a file. The mapped area is updated back to disk.

inline void  Sync (void)

Sync

Synchronize the contents of the mapped portion of memory with the disk file and wait for completion. This assures the memory mapped from the file is written back.

void  Sync (char * address, size_t len)

Sync

Synchronize a segment of memory mapped from a segment fetch.

Parameters:
memoryaddress to update.
sizeof segment.

void  Update (size_t offset = 0, size_t len = 0)

Update

Map a portion of the memory mapped from the file back to the file and do not wait for completion. This is useful when mapping a database file and updating a single record.

Parameters:
offsetinto the mapped region of memory.
lenof partial region (example, record length).

void  Update (char * address, size_t len)

Update

Update a mapped region back to disk as specified by address and length.

Parameters:
addressof segment.
lengthof segment.

void  Release (char * address, size_t len)

Release

Release (unmap) a memory segment.

Parameters:
addressof memory segment to release.
lengthof memory segment to release.

inline char *  Fetch (size_t offset = 0)

Fetch

Fetch a pointer to an offset within the memory mapped portion of the disk file. This really is used for convience of matching operations between Update and Fetch, as one could simply have accessed the base pointer where the file was mapped directly.

Parameters:
offsetfrom start of mapped memory.

char *  Fetch (off_t pos, size_t len)

Fetch

Fetch and map a portion of a disk file to a logical memory block.

Parameters:
offsetof file segment to map.
sizeof memory segment to map.

Returns: pointer to memory segment.

 MappedFile (const char *fname, fileaccess_t mode)

MappedFile

Open a file for mapping. More than one segment of a file may be mapped into seperate regions of memory.

Parameters:
filename to access for mapping.
accessmode to map file.

 MappedFile (const char *fname, pos_t offset, size_t size, fileaccess_t mode)

MappedFile

Map a portion or all of a specified file in the specified shared memory access mode. Valid mapping modes include FILE_MAPPED_READ, FILE_MAPPED_WRITE, and FILE_MAPPED_RDWR.

Parameters:
fnamepathname of file to map into memory.
offsetfrom start of file to begin mapping in bytes.
sizeof mapped area in bytes.
modeto map file.

 ~MappedFile ()

~MappedFile

[virtual]

Release a mapped section of memory associated with a file. The mapped area is updated back to disk.

inline void  Sync (void)

Sync

Synchronize the contents of the mapped portion of memory with the disk file and wait for completion. This assures the memory mapped from the file is written back.

void  Sync (char * address, size_t len)

Sync

Synchronize a segment of memory mapped from a segment fetch.

Parameters:
memoryaddress to update.
sizeof segment.

void  Update (size_t offset = 0, size_t len = 0)

Update

Map a portion of the memory mapped from the file back to the file and do not wait for completion. This is useful when mapping a database file and updating a single record.

Parameters:
offsetinto the mapped region of memory.
lenof partial region (example, record length).

void  Update (char * address, size_t len)

Update

Update a mapped region back to disk as specified by address and length.

Parameters:
addressof segment.
lengthof segment.

void  Release (char * address, size_t len)

Release

Release (unmap) a memory segment.

Parameters:
addressof memory segment to release.
lengthof memory segment to release.

inline char *  Fetch (size_t offset = 0)

Fetch

Fetch a pointer to an offset within the memory mapped portion of the disk file. This really is used for convience of matching operations between Update and Fetch, as one could simply have accessed the base pointer where the file was mapped directly.

Parameters:
offsetfrom start of mapped memory.

char *  Fetch (off_t pos, size_t len)

Fetch

Fetch and map a portion of a disk file to a logical memory block.

Parameters:
offsetof file segment to map.
sizeof memory segment to map.

Returns: pointer to memory segment.