casacore
|
Memory-mapped IO on a file. More...
#include <MMapIO.h>
Public Member Functions | |
MMapIO (const RegularFile ®ularFile, ByteIO::OpenOption=ByteIO::Old) | |
Open the given file and map it entirely into memory with read access. More... | |
~MMapIO () | |
Destructor. More... | |
Public Member Functions inherited from casacore::MMapfdIO | |
MMapfdIO () | |
Default constructor. More... | |
MMapfdIO (int fd, const String &fileName) | |
Map the given file descriptor entirely into memory with read access. More... | |
~MMapfdIO () | |
Destructor. More... | |
void | map (int fd, const String &fileName) |
Map the given file descriptor entirely into memory with read access. More... | |
void | mapFile () |
Map or remap the entire file. More... | |
void | flush () |
Flush changed mapped data to the file. More... | |
virtual void | write (Int64 size, const void *buf) |
Write the number of bytes from the seek position on. More... | |
virtual Int64 | read (Int64 size, void *buf, Bool throwException=True) |
Read size bytes from the File. More... | |
const void * | getReadPointer (Int64 offset) const |
Get a read or write pointer to the given position in the mapped file. More... | |
void * | getWritePointer (Int64 offset) |
Int64 | getFileSize () const |
Get the file size. More... | |
Public Member Functions inherited from casacore::FiledesIO | |
FiledesIO () | |
Default constructor. More... | |
FiledesIO (int fd, const String &fileName=String()) | |
Construct from the given file descriptor. More... | |
void | attach (int fd, const String &fileName) |
Attach to the given file descriptor. More... | |
void | detach () |
Detach from the file descriptor. More... | |
virtual | ~FiledesIO () |
The destructor detaches, but does not close the file. More... | |
virtual void | pwrite (Int64 size, Int64 offset, const void *buf) |
Write the number of bytes at offset from start of the file. More... | |
virtual Int64 | pread (Int64 size, Int64 offset, void *buf, Bool throwException=True) |
Like read except reads from offset of the start of the file. More... | |
virtual Int64 | length () |
Get the length of the byte stream. More... | |
virtual Bool | isReadable () const |
Is the IO stream readable? More... | |
virtual Bool | isWritable () const |
Is the IO stream writable? More... | |
virtual Bool | isSeekable () const |
Is the IO stream seekable? More... | |
void | setWritable () |
Set that the IO stream is writable. More... | |
virtual String | fileName () const |
Get the file name of the file attached. More... | |
virtual void | fsync () |
Fsync the file (i.e. More... | |
Public Member Functions inherited from casacore::ByteIO | |
ByteIO () | |
The constructor does nothing. More... | |
virtual | ~ByteIO () |
virtual void | reopenRW () |
Reopen the underlying IO stream for read/write access. More... | |
Int64 | seek (Int offset, ByteIO::SeekOption=ByteIO::Begin) |
This function sets the position on the given offset. More... | |
Int64 | seek (Int64 offset, ByteIO::SeekOption=ByteIO::Begin) |
virtual void | resync () |
Resync the file (i.e. More... | |
Private Member Functions | |
MMapIO (const MMapIO &) | |
Forbid copy constructor and assignment. More... | |
MMapIO & | operator= (const MMapIO &) |
Additional Inherited Members | |
Public Types inherited from casacore::ByteIO | |
enum | OpenOption { Old, Update, Append, New, NewNoReplace, Scratch, Delete } |
Define the possible ByteIO open options. More... | |
enum | SeekOption { Begin, Current, End } |
Define the possible seek options. More... | |
Static Public Member Functions inherited from casacore::FiledesIO | |
static int | create (const Char *name, int mode=0666) |
Some static convenience functions for file create/open/close. More... | |
static int | open (const Char *name, Bool writable=False, Bool throwExcp=True) |
static void | close (int fd) |
Protected Member Functions inherited from casacore::MMapfdIO | |
virtual Int64 | doSeek (Int64 offset, ByteIO::SeekOption) |
Reset the position pointer to the given value. More... | |
void | unmapFile () |
Unmap the file. More... | |
Protected Member Functions inherited from casacore::FiledesIO | |
int | fd () const |
Get the file descriptor. More... | |
void | fillRWFlags (int fd) |
Determine if the file descriptor is readable and/or writable. More... | |
void | fillSeekable () |
Determine if the file is seekable. More... | |
Protected Member Functions inherited from casacore::ByteIO | |
ByteIO (const ByteIO &byteIO) | |
Make copy constructor and assignment protected, so a user cannot use them (but a derived class can). More... | |
ByteIO & | operator= (const ByteIO &byteIO) |
Memory-mapped IO on a file.
Memory-mapped IO lets the OS take care of caching file segments. This is particularly useful for the Tiled Storage Manager which keeps a cache of tiles. When using memory-mapped IO it does not need to do that anymore.
On 32-bit systems its use is limited because for large files the 4 GB memory space is insufficient. However, for 64-bit systems the memory space is large enough to make use of it.
In the general case there is direct access to the mapped file space. The read and write methods copies the data into/from a buffer. However, to avoid the copying it is possible to get a direct pointer to the mapped data. This should be used with care, because writing to it will cause a segmentation if the file is readonly. If the file is writable, writing into the mapped data segment means changing the file contents.
|
explicit |
Open the given file and map it entirely into memory with read access.
The map has write access if the file is opened for write.
casacore::MMapIO::~MMapIO | ( | ) |
Destructor.
It will flush and unmap the file.
|
private |
Forbid copy constructor and assignment.