next up previous contents index
Next: SortedTable Classes Up: Utility Classes Previous: Utility Classes

MMap Class

  


  
Figure 3.1: MMap Class
\begin{figure}
\begin{center}

\includegraphics [scale=1]{MMap.ps}
\end{center}\end{figure}

The class MMap is the wrapper class for the mmap() system call (See Section 2.3.3) and its relatives. The summary of the interface is shown in Figure 3.1.

There are three constructors for the class. One is for the first mapping of a file whose name is specified in the first parameter. The constructor opens the file in the mode specified in the second parameter. The file descriptor is stored in the member fd. The protection mode and the mapping flags are appropriately determined and stored in the member prot and flags. When the file is /dev/zero, the member flags is configured as copy-on-write for implementation of non-persistent mapping. The file name is stored in the member fileName.

Other constructors are for inheritance of another MMap instance or a file descriptor. The file name and the mapping are not inherited from the instance.

The destructor unmaps the mapping if mapped, and closes the file if the fileName is not null, which means that the instance has opened the file.

The operation map(offset, length) maps the specified region of the file in a region in the main memory by the mmap() system call. The starting address of the region can be obtained via the accessor getAddr().

The operation unmap() unmaps the mapped region by the munmap() system call. The operation sync() synchronizes the region in the main memory with the file. The synchronization is either synchronously or asynchronously scheduled.


next up previous contents index
Next: SortedTable Classes Up: Utility Classes Previous: Utility Classes
Mori Tetsuya / t2y3141592@gmail.com