FileMapping
Encapsulates file mapping of file to memory (Linux mmap, Win32 CreateFileMapping) in mostly platform independent way.
FileMapping(const char *file = 0)
Constructs the class; if file is not NULL, calls Open(file).
bool Open(const char *filename, dword mode = FileStream::READ, int64 filesize = 0)
Opens filename for file mapping. mode is a combination of flags defined in BlockStream. If the mode contrains CREATE flag, filesize is a size of newly created file. If any file mapping was open before Open open, it is closed first.
bool Create(const char *file, int64 filesize)
Same as Open(file, FileStream::CREATE, filesize).
int64 GetFileSize() const
Returns the current file size.
Time GetTime() const
Returns the last modification time.
byte *Map(int64 mapoffset, size_t maplen)
Maps a portion file starting at mapoffset with size maplen to memory. No alignment rules are required for mapoffset and maplen (FileMapping maps bigger chunk of file if necessarry).
byte *Map()
Same as Map(0, GetFileSize()) - maps the whole file. Probably the best mode with 64 bit platforms with relatively unlimited virtual space.
bool Unmap()
Ends file mapping (and writes changes to disk).
bool Close()
Closes the file.
bool IsOpen() const
Returns true if there is open file in FileMapping.
int64 GetOffset() const
Returns mapoffset from the Map call.
size_t GetCount() const
Returns maplen from the Map call.
const byte *operator~() const
const byte *begin() const
byte *operator~()
byte *begin()
Returns a pointer to the mapped file content or NULL if there is no mapping.
const byte *end() const
byte *end()
Same as begin() + GetCount().
const byte& operator[](int i) const
byte& operator[](int i)
Same as begin()[i].
|