Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

MappedFile Class Reference

Create and map a disk file into memory. Map a named disk file into memory. More...

#include <file.h>

Inheritance diagram for MappedFile::

RandomFile Mutex List of all members.

Public Methods

 MappedFile (const char *fname, fileaccess_t mode)
 Open a file for mapping. More...

 MappedFile (const char *fname, pos_t offset, size_t size, fileaccess_t mode)
 Map a portion or all of a specified file in the specified shared memory access mode. More...

virtual ~MappedFile ()
 Release a mapped section of memory associated with a file. More...

void Sync (void)
 Synchronize the contents of the mapped portion of memory with the disk file and wait for completion. More...

void Sync (char *address, size_t len)
 Synchronize a segment of memory mapped from a segment fetch. More...

void Update (size_t offset=0, size_t len=0)
 Map a portion of the memory mapped from the file back to the file and do not wait for completion. More...

void Update (char *address, size_t len)
 Update a mapped region back to disk as specified by address and length. More...

void Release (char *address, size_t len)
 Release (unmap) a memory segment. More...

char * Fetch (size_t offset=0)
 Fetch a pointer to an offset within the memory mapped portion of the disk file. More...

char * Fetch (off_t pos, size_t len)
 Fetch and map a portion of a disk file to a logical memory block. More...


Detailed Description

Create and map a disk file into memory. Map a named 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().

Author:
David Sugar <dyfet@ostel.com>


Constructor & Destructor Documentation

MappedFile::MappedFile const char *   fname,
fileaccess_t   mode
 

Open a file for mapping.

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

Parameters:
file   name to access for mapping.
access   mode to map file.

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

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:
fname   pathname of file to map into memory.
offset   from start of file to begin mapping in bytes.
size   of mapped area in bytes.
mode   to map file.

virtual MappedFile::~MappedFile   [virtual]
 

Release a mapped section of memory associated with a file.

The mapped area is updated back to disk.


Member Function Documentation

char* MappedFile::Fetch off_t   pos,
size_t   len
 

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

Returns:
pointer to memory segment.
Parameters:
offset   of file segment to map.
size   of memory segment to map.

char* MappedFile::Fetch size_t   offset = 0 [inline]
 

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:
offset   from start of mapped memory.

void MappedFile::Release char *   address,
size_t   len
 

Release (unmap) a memory segment.

Parameters:
address   of memory segment to release.
length   of memory segment to release.

void MappedFile::Sync char *   address,
size_t   len
 

Synchronize a segment of memory mapped from a segment fetch.

Parameters:
memory   address to update.
size   of segment.

void MappedFile::Sync void   [inline]
 

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 MappedFile::Update char *   address,
size_t   len
 

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

Parameters:
address   of segment.
length   of segment.

void MappedFile::Update size_t   offset = 0,
size_t   len = 0
 

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:
offset   into the mapped region of memory.
len   of partial region (example, record length).


The documentation for this class was generated from the following file:
Generated at Tue Nov 20 12:34:35 2001 for CommonC++ by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001