SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
List of all members | Public Member Functions | Protected Attributes
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]

Public Member Functions

 CMemoryMappedFile ()
 CMemoryMappedFile (const char *fname, char flag='r', int64_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[] (uint64_t index) const
operator[] (int32_t index) const
virtual const char * get_name () const
- Public Member Functions inherited from CSGObject
 CSGObject ()
 CSGObject (const CSGObject &orig)
virtual ~CSGObject ()
virtual bool is_generic (EPrimitiveType *generic) const
template<class T >
void set_generic ()
void unset_generic ()
virtual void print_serializable (const char *prefix="")
virtual bool save_serializable (CSerializableFile *file, const char *prefix="")
virtual bool load_serializable (CSerializableFile *file, const char *prefix="")
void set_global_io (SGIO *io)
SGIOget_global_io ()
void set_global_parallel (Parallel *parallel)
Parallelget_global_parallel ()
void set_global_version (Version *version)
Versionget_global_version ()
SGVector< char * > get_modelsel_names ()
char * get_modsel_param_descr (const char *param_name)
index_t get_modsel_param_index (const char *param_name)

Protected Attributes

int fd
uint64_t length
void * address
char rw
uint64_t last_written_byte

Additional Inherited Members

- Public Attributes inherited from CSGObject
SGIOio
Parallelparallel
Versionversion
Parameterm_parameters
Parameterm_model_selection_parameters
- Protected Member Functions inherited from CSGObject
virtual void load_serializable_pre () throw (ShogunException)
virtual void load_serializable_post () throw (ShogunException)
virtual void save_serializable_pre () throw (ShogunException)
virtual void save_serializable_post () throw (ShogunException)

Constructor & Destructor Documentation

default constructor

Definition at line 35 of file MemoryMappedFile.h.

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

constructor

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

Parameters
fnamename of file, zero terminated string
flagdetermines read or read write mode (can be 'r' or 'w')
fsizeoverestimate 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 60 of file MemoryMappedFile.h.

virtual ~CMemoryMappedFile ( )
virtual

destructor

Definition at line 107 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 137 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
lenlength of line (returned via reference)
offsoffset to be passed for reading next line, should be 0 initially (returned via reference)
Returns
line (NOT ZERO TERMINATED)

Definition at line 162 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 128 of file MemoryMappedFile.h.

virtual const char* get_name ( ) const
virtual
Returns
object name

Implements CSGObject.

Definition at line 263 of file MemoryMappedFile.h.

int32_t get_num_lines ( )

count the number of lines in a file

Returns
number of lines

Definition at line 225 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 146 of file MemoryMappedFile.h.

T operator[] ( uint64_t  index) const

operator overload for file read only access

DOES NOT DO ANY BOUNDS CHECKING

Parameters
indexindex
Returns
element at index

Definition at line 245 of file MemoryMappedFile.h.

T operator[] ( int32_t  index) const

operator overload for file read only access

DOES NOT DO ANY BOUNDS CHECKING

Parameters
indexindex
Returns
element at index

Definition at line 257 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
szbyte 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 216 of file MemoryMappedFile.h.

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

write line to file

Parameters
linestring to be written (must not contain '
' and not required to be zero terminated)
lenlength of the string to be written
offsoffset to be passed for writing next line, should be 0 initially (returned via reference)
Returns
line (NOT ZERO TERMINATED)

Definition at line 191 of file MemoryMappedFile.h.

Member Data Documentation

void* address
protected

mapping address

Definition at line 271 of file MemoryMappedFile.h.

int fd
protected

file descriptor

Definition at line 267 of file MemoryMappedFile.h.

uint64_t last_written_byte
protected

last_written_byte

Definition at line 276 of file MemoryMappedFile.h.

uint64_t length
protected

size of file

Definition at line 269 of file MemoryMappedFile.h.

char rw
protected

mode

Definition at line 273 of file MemoryMappedFile.h.


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

SHOGUN Machine Learning Toolbox - Documentation