GMMap Class Reference

[libgfc Index] [libgfc Hierarchy] [Headers]


portable memory mapping class More...

#include <utils/src/gmmap.h>

Public Members


Detailed Description

portable memory mapping class.


GMMap(const char* file) [public]

default constructor. It needs the name of the file to be mapped. The constructor does not acutally open the file and map it into memory. Use the mehtod map for this purpose.

Parameters:
file is the file to be mapped.

~GMMap() [public]

destructor unmap and close the file if still mapped.

int map(off_t off, size_t len, const char* ps=0) [public]

map the portion [offset, offset+len] of 'file' to memory. If the file is already mapped, it will be unmap()'ed first before re-mapping it. returns 1 if succeed; otherwise 0.

Parameters:
ps is the protection string similar to the access flag of the open(). It can be "r", "w", "x" and the combinations.

int mapAll(const char* ps=0) [public]

map the full length of the file. This is equivalent to map(0, file_length, ps).

int extendMap(int size_inc, long off=-1, long len=-1) [public]

extend the file and mmap the file again. If off and len are both negative then simply mmap() the whole extended file. This is useful when the file needs to grow in size while being mapped in memory.

Parameters:
size_inc is the size to extend the file.

int unmap() [public]

unmap the file and release the mapped region. returns 1 if success; otherwise 0.

int advise(int advice) [public]

gives Operating system some advice about the mapped memory usage.

Parameters:
advice is the advice to be given to the VM system. possible advices are: MADV_NORMAL (0x0) MADV_RNADOM (0x1) MADV_SEQUENTIAl (0x2) MADV_WILLNEED (0x3) MADV_DONTNEED (0x4) return 1 if success, otherwise 0.

void setFlag(const char* fs ) [public]

set the flag for mapping. the flag affects only the next mmap() calls. Default is "s" for SHARED mapping. Other settings are: "p" for PRIVATE, "f" for FIXED, "n" for NORESEVE.

void setProtection(const char* ps) [public]

set the protection for mapping. the flag affects only the next mmap() call. Default is PROT_READ|PROT_WRITE.

void* ptr() [public]

return the pointer to the start position of mmaped memory.

int len() const [public]

return the length of the current mmaped region. access beyond the ptr()+len() is illeagl.

int fileDesc() const [public]

return the file descriptor


Documentation generated by lqian@lqian-sun on Wed Jul 14 09:36:10 EDT 1999
Kdoc