Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.atnf.csiro.au/computing/software/casacore/casacore-1.2.0/doc/html/classcasa_1_1MMapfdIO.html
Дата изменения: Unknown
Дата индексирования: Mon Feb 14 21:06:44 2011
Кодировка:

Поисковые слова: m 103
casacore: casa::MMapfdIO Class Reference
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes

casa::MMapfdIO Class Reference
[IO_module]

Memory-mapped IO on a file. More...

#include <MMapfdIO.h>

Inheritance diagram for casa::MMapfdIO:
casa::LargeFiledesIO casa::ByteIO casa::MMapIO

List of all members.

Public Member Functions

 MMapfdIO ()
 Default constructor.
 MMapfdIO (int fd, const String &fileName)
 Map the given file descriptor entirely into memory with read access.
 ~MMapfdIO ()
 Destructor.
void map (int fd, const String &fileName)
 Map the given file descriptor entirely into memory with read access.
void mapFile ()
 Map or remap the entire file.
void flush ()
 Flush changed mapped data to the file.
virtual void write (uInt size, const void *buf)
 Write the number of bytes from the seek position on.
virtual Int read (uInt size, void *buf, Bool throwException=True)
 Read size bytes from the File.
const void * getReadPointer (Int64 offset) const
 Get a read or write pointer to the given position in the mapped file.
void * getWritePointer (Int64 offset)
Int64 getFileSize () const
 Get the file size.

Protected Member Functions

virtual Int64 doSeek (Int64 offset, ByteIO::SeekOption)
 Reset the position pointer to the given value.
void unmapFile ()
 Unmap the file.

Private Member Functions

 MMapfdIO (const MMapfdIO &)
 Forbid copy constructor and assignment.
MMapfdIOoperator= (const MMapfdIO &)

Private Attributes

Int64 itsFileSize
Int64 itsPosition
char * itsPtr
Bool itsIsWritable

Detailed Description

Memory-mapped IO on a file.

Synopsis

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.

Definition at line 62 of file MMapfdIO.h.


Constructor & Destructor Documentation

casa::MMapfdIO::MMapfdIO (  ) 

Default constructor.

A file can be memory-mapped using the map function.

casa::MMapfdIO::MMapfdIO ( int  fd,
const String fileName 
)

Map the given file descriptor entirely into memory with read access.

The map has also write access if the file is opened for write. The file name is only used in possible error messages.

casa::MMapfdIO::~MMapfdIO (  ) 

Destructor.

If needed, it will flush and unmap the file, but not close it.

casa::MMapfdIO::MMapfdIO ( const MMapfdIO  )  [private]

Forbid copy constructor and assignment.


Member Function Documentation

virtual Int64 casa::MMapfdIO::doSeek ( Int64  offset,
ByteIO::SeekOption   
) [protected, virtual]

Reset the position pointer to the given value.

It returns the new position.

Reimplemented from casa::LargeFiledesIO.

void casa::MMapfdIO::flush (  ) 

Flush changed mapped data to the file.

Nothing is done if the file is readonly.

Int64 casa::MMapfdIO::getFileSize (  )  const [inline]

Get the file size.

Definition at line 118 of file MMapfdIO.h.

References itsFileSize.

const void* casa::MMapfdIO::getReadPointer ( Int64  offset  )  const

Get a read or write pointer to the given position in the mapped file.

An exception is thrown if beyond end-of-file or it not writable. These functions should be used with care. If the pointer is used to access data beyond the file size, a segmentation fault will occur. So it means that the write pointer can only be used to update the file, not to extend it. The seek and write functions should be used to extend a file.

void* casa::MMapfdIO::getWritePointer ( Int64  offset  ) 
void casa::MMapfdIO::map ( int  fd,
const String fileName 
)

Map the given file descriptor entirely into memory with read access.

The map has also write access if the file is opened for write. An exception is thrown if a file descriptor was already attached. The file name is only used in possible error messages.

void casa::MMapfdIO::mapFile (  ) 

Map or remap the entire file.

Remapping is needed if the file has grown elsewhere.

MMapfdIO& casa::MMapfdIO::operator= ( const MMapfdIO  )  [private]
virtual Int casa::MMapfdIO::read ( uInt  size,
void *  buf,
Bool  throwException = True 
) [virtual]

Read size bytes from the File.

Returns the number of bytes actually read. Will throw an exception (AipsError) if the requested number of bytes could not be read unless throwException is set to False. Will always throw an exception if the file is not readable or the system call returns an undocumented value.

Reimplemented from casa::LargeFiledesIO.

void casa::MMapfdIO::unmapFile (  )  [protected]

Unmap the file.

virtual void casa::MMapfdIO::write ( uInt  size,
const void *  buf 
) [virtual]

Write the number of bytes from the seek position on.

The file will be extended and remapped if writing beyond end-of-file. In that case possible pointers obtained using getXXPointer are not valid anymore.

Reimplemented from casa::LargeFiledesIO.


Member Data Documentation

Definition at line 136 of file MMapfdIO.h.

Referenced by getFileSize().

Definition at line 139 of file MMapfdIO.h.

Definition at line 137 of file MMapfdIO.h.

char* casa::MMapfdIO::itsPtr [private]

Definition at line 138 of file MMapfdIO.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines