memory mapped file
Implements a memory mapped file for super fast file access.
在文件MemoryMappedFile.h第31行定义。
公有成员 | |
CMemoryMappedFile (const char *fname, char flag='r', uint64_t fsize=0) | |
virtual | ~CMemoryMappedFile () |
T * | get_map () |
uint64_t | get_length () |
uint64_t | get_size () |
char * | get_line (uint64_t &len, uint64_t &offs) |
void | write_line (const char *line, uint64_t len, uint64_t &offs) |
void | set_truncate_size (uint64_t *sz=0) |
int32_t | get_num_lines () |
T | operator[] (uint64_t index) const |
T | operator[] (int32_t index) const |
virtual const char * | get_name () const |
保护属性 | |
int | fd |
uint64_t | length |
void * | address |
char | rw |
uint64_t | last_written_byte |
CMemoryMappedFile | ( | const char * | fname, |
char | flag = 'r' , |
||
uint64_t | fsize = 0 |
||
) |
constructor
open a memory mapped file for read or read/write mode
fname | name of file, zero terminated string |
flag | determines read or read write mode (can be 'r' or 'w') |
fsize | overestimate of expected file size (in bytes) when opened in write mode; Underestimating the file size will result in an error to occur upon writing. In case the exact file size is known later on, it can be reduced via set_truncate_size() before closing the file. |
在文件MemoryMappedFile.h第47行定义。
virtual ~CMemoryMappedFile | ( | ) | [virtual] |
destructor
在文件MemoryMappedFile.h第94行定义。
uint64_t get_length | ( | ) |
get the number of objects of type T cointained in the file
在文件MemoryMappedFile.h第124行定义。
char* get_line | ( | uint64_t & | len, |
uint64_t & | offs | ||
) |
get next line from file
The returned line may be modfied in case the file was opened read/write. It is otherwise read-only.
len | length of line (returned via reference) |
offs | offset to be passed for reading next line, should be 0 initially (returned via reference) |
在文件MemoryMappedFile.h第149行定义。
T* get_map | ( | ) |
get the mapping address It can now be accessed via, e.g.
double* x = get_map() x[index]= foo; (for write mode) foo = x[index]; (for read and write mode)
在文件MemoryMappedFile.h第115行定义。
virtual const char* get_name | ( | ) | const [virtual] |
int32_t get_num_lines | ( | ) |
uint64_t get_size | ( | ) |
T operator[] | ( | int32_t | index ) | const |
operator overload for file read only access
DOES NOT DO ANY BOUNDS CHECKING
index | index |
在文件MemoryMappedFile.h第244行定义。
T operator[] | ( | uint64_t | index ) | const |
operator overload for file read only access
DOES NOT DO ANY BOUNDS CHECKING
index | index |
在文件MemoryMappedFile.h第232行定义。
void set_truncate_size | ( | uint64_t * | sz = 0 ) |
set file size
When the file is opened for read/write mode, it will be truncated upon destruction of the CMemoryMappedFile object. This is automagically determined when writing lines, but might have to be set manually for other data types, which is what this function is for.
sz | byte number at which to truncate the file, zero to disable file truncation. Has an effect only when file is opened with in read/write mode 'w' |
在文件MemoryMappedFile.h第203行定义。
void write_line | ( | const char * | line, |
uint64_t | len, | ||
uint64_t & | offs | ||
) |
write line to file
line | string to be written (must not contain ' ' and not required to be zero terminated) |
len | length of the string to be written |
offs | offset to be passed for writing next line, should be 0 initially (returned via reference) |
在文件MemoryMappedFile.h第178行定义。
void* address [protected] |
mapping address
在文件MemoryMappedFile.h第258行定义。
int fd [protected] |
file descriptor
在文件MemoryMappedFile.h第254行定义。
uint64_t last_written_byte [protected] |
last_written_byte
在文件MemoryMappedFile.h第263行定义。
uint64_t length [protected] |
size of file
在文件MemoryMappedFile.h第256行定义。
char rw [protected] |
mode
在文件MemoryMappedFile.h第260行定义。