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.


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

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:56:44 2008 by Doxygen version 1.5.5.