CMemoryMappedFile< T > Class Template Reference


Detailed Description

template<class T>
class shogun::CMemoryMappedFile< T >

memory mapped file

Implements a memory mapped file for super fast file access.

Definition at line 31 of file MemoryMappedFile.h.

Inheritance diagram for CMemoryMappedFile< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 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 ()
operator[] (int32_t index) const
virtual const char * get_name () const

Protected Attributes

int fd
uint64_t length
void * address
char rw
uint64_t last_written_byte

Constructor & Destructor Documentation

CMemoryMappedFile ( const char *  fname,
char  flag = 'r',
uint64_t  fsize = 0 
)

constructor

open a memory mapped file for read or read/write mode

Parameters:
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.

Definition at line 47 of file MemoryMappedFile.h.

virtual ~CMemoryMappedFile (  )  [virtual]

destructor

Definition at line 94 of file MemoryMappedFile.h.


Member Function Documentation

uint64_t get_length (  ) 

get the number of objects of type T cointained in the file

Returns:
length of file

Definition at line 124 of file MemoryMappedFile.h.

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.

Parameters:
len length of line (returned via reference)
offs offset to be passed for reading next line, should be 0 initially (returned via reference)
Returns:
line (NOT ZERO TERMINATED)

Definition at line 149 of file MemoryMappedFile.h.

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)

Returns:
length of file

Definition at line 115 of file MemoryMappedFile.h.

virtual const char* get_name (  )  const [virtual]
Returns:
object name

Implements CSGObject.

Definition at line 238 of file MemoryMappedFile.h.

int32_t get_num_lines (  ) 

count the number of lines in a file

Returns:
number of lines

Definition at line 212 of file MemoryMappedFile.h.

uint64_t get_size (  ) 

get the size of the file in bytes

Returns:
size of file in bytes

Definition at line 133 of file MemoryMappedFile.h.

T operator[] ( int32_t  index  )  const

operator overload for file read only access

DOES NOT DO ANY BOUNDS CHECKING

Parameters:
index index
Returns:
element at index

Definition at line 232 of file MemoryMappedFile.h.

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.

Parameters:
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'

Definition at line 203 of file MemoryMappedFile.h.

void write_line ( const char *  line,
uint64_t  len,
uint64_t &  offs 
)

write line to file

Parameters:
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)
Returns:
line (NOT ZERO TERMINATED)

Definition at line 178 of file MemoryMappedFile.h.


Member Data Documentation

void* address [protected]

mapping address

Definition at line 246 of file MemoryMappedFile.h.

int fd [protected]

file descriptor

Definition at line 242 of file MemoryMappedFile.h.

uint64_t last_written_byte [protected]

last_written_byte

Definition at line 251 of file MemoryMappedFile.h.

uint64_t length [protected]

size of file

Definition at line 244 of file MemoryMappedFile.h.

char rw [protected]

mode

Definition at line 248 of file MemoryMappedFile.h.


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

SHOGUN Machine Learning Toolbox - Documentation