#include <rutz/mappedfile.h>
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. |
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.
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.