NPL
Neurological Programs and Libraries
npl::MemMap Class Reference

Memory map class. The basic gyst is that this works like a malloc except that data may be initialized by file contents or left empty. This is useful for matrix manipulation where files need to be opened and closed a good bit. More...

#include <utility.h>

Public Member Functions

 MemMap (std::string fn, size_t bsize)
 Create a new mmap class by opening the specified file with the specified size. This version ALWAYS CREATES A NEW FILE. THIS WILL OVERWRITE THE OLD FILE. More...
 
 MemMap (std::string fn, bool writeable=false)
 Open an example file as a memory map. More...
 
 MemMap ()
 Just create the object. Until open() is called the size() will be 0 and returned data() will be NULL;. More...
 
int64_t openNew (std::string fn, size_t bsize)
 Open the specified file with the specified size. If createNew is set then a new file will be created an existing file will be deleted (if permissions allow it). This is always opened as writeable. More...
 
int64_t openExisting (std::string fn, bool writeable, bool quiet=true)
 Open the specified file with the specified size. If createNew is set then a new file will be created an existing file will be deleted (if permissions allow it). More...
 
bool isopen ()
 Return true if a file is currently open. More...
 
void close ()
 Close the current file (if one is open). data() will return NULL and size() will return 0 after this until open() is called again. More...
 
 ~MemMap ()
 Destructor, close file. More...
 
void * data ()
 Get pointer to data. More...
 
const void * data () const
 Get constant pointer to current data. More...
 
int64_t size ()
 Length (in bytes) of memory map. More...
 

Detailed Description

Memory map class. The basic gyst is that this works like a malloc except that data may be initialized by file contents or left empty. This is useful for matrix manipulation where files need to be opened and closed a good bit.

Definition at line 276 of file utility.h.

Constructor & Destructor Documentation

npl::MemMap::MemMap ( std::string  fn,
size_t  bsize 
)

Create a new mmap class by opening the specified file with the specified size. This version ALWAYS CREATES A NEW FILE. THIS WILL OVERWRITE THE OLD FILE.

Parameters
fnOpen the specified file for reading and writing.
bsizeMake the file size this number of bytes.
npl::MemMap::MemMap ( std::string  fn,
bool  writeable = false 
)

Open an example file as a memory map.

Parameters
fnOpen the specified file for reading and writing.
writeableWhether the opened file will be writeable. Note that no two processes should have the same file open as writeable at a time.
npl::MemMap::MemMap ( )
inline

Just create the object. Until open() is called the size() will be 0 and returned data() will be NULL;.

Definition at line 303 of file utility.h.

npl::MemMap::~MemMap ( )

Destructor, close file.

Member Function Documentation

void npl::MemMap::close ( )

Close the current file (if one is open). data() will return NULL and size() will return 0 after this until open() is called again.

void* npl::MemMap::data ( )
inline

Get pointer to data.

Returns
pointer to current data

Definition at line 351 of file utility.h.

const void* npl::MemMap::data ( ) const
inline

Get constant pointer to current data.

Returns
pointer to current data

Definition at line 358 of file utility.h.

bool npl::MemMap::isopen ( )
inline

Return true if a file is currently open.

Definition at line 333 of file utility.h.

int64_t npl::MemMap::openExisting ( std::string  fn,
bool  writeable,
bool  quiet = true 
)

Open the specified file with the specified size. If createNew is set then a new file will be created an existing file will be deleted (if permissions allow it).

Parameters
fnOpen the specified file for reading.
writeablewhether the opened file will be writeable (note that no two processes should open the same file as writeable)
quietWhether to print errors when we can't open a file
Returns
size of memory map
int64_t npl::MemMap::openNew ( std::string  fn,
size_t  bsize 
)

Open the specified file with the specified size. If createNew is set then a new file will be created an existing file will be deleted (if permissions allow it). This is always opened as writeable.

Parameters
fnOpen the specified file for reading and writing.
bsizeMake the file size this number of bytes. If createNew is false then this must match the current file size
Returns
size of memory map
int64_t npl::MemMap::size ( )
inline

Length (in bytes) of memory map.

0 not error, but not open >0 open -1 error

Returns
Tells what the current state of the memory map is

Definition at line 369 of file utility.h.


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