rutz::mapped_infile Class Reference

An mmap()/munmap() wrapper class for fast input file reading. More...

#include <rutz/mappedfile.h>

List of all members.

Public Member Functions

 mapped_infile (const char *filename)
 Open the named file using mmap().
 ~mapped_infile ()
 Destructor closes and munmap()'s the file.
const void * memory () const
 Get a pointer to the memory representing the file contents.
off_t length () const
 Get the length of the file, and of its in-memory representation.
time_t mtime () const
 Get the last-modification time of the file.

Detailed Description

An mmap()/munmap() wrapper class for fast input file reading.

In cases where an entire file would eventually be read into memory anyway, it is likely to be significantly faster (2-3x faster at least) to use mmap-ing instead of C-style fopen()/fgetc()/fread()/fclose() or C++-style iostreams. This is because both the C and C++ libraries are likely implemented internally with mmap anyway, and those libraries introduce another layer of memory buffering on top of the raw OS mmap.

Definition at line 48 of file mappedfile.h.


Constructor & Destructor Documentation

rutz::mapped_infile::mapped_infile ( const char *  filename  ) 

Open the named file using mmap().

The contents of the file become accessible as if the file were laid out continously in memory.

Definition at line 47 of file mappedfile.cc.

References rutz::sfmt(), and SRC_POS.

rutz::mapped_infile::~mapped_infile (  ) 

Destructor closes and munmap()'s the file.

Definition at line 81 of file mappedfile.cc.


Member Function Documentation

off_t rutz::mapped_infile::length ( void   )  const [inline]

Get the length of the file, and of its in-memory representation.

Definition at line 63 of file mappedfile.h.

const void* rutz::mapped_infile::memory (  )  const [inline]

Get a pointer to the memory representing the file contents.

Definition at line 60 of file mappedfile.h.

time_t rutz::mapped_infile::mtime (  )  const [inline]

Get the last-modification time of the file.

Definition at line 66 of file mappedfile.h.


The documentation for this class was generated from the following files:
Generated on Sun May 8 08:44:44 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3