00001 //# MMapIO.h: Memory-mapped IO on a file 00002 //# 00003 //# Copyright (C) 2009 00004 //# Associated Universities, Inc. Washington DC, USA. 00005 //# 00006 //# This library is free software; you can redistribute it and/or modify it 00007 //# under the terms of the GNU Library General Public License as published by 00008 //# the Free Software Foundation; either version 2 of the License, or (at your 00009 //# option) any later version. 00010 //# 00011 //# This library is distributed in the hope that it will be useful, but WITHOUT 00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 //# License for more details. 00015 //# 00016 //# You should have received a copy of the GNU Library General Public License 00017 //# along with this library; if not, write to the Free Software Foundation, 00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00019 //# 00020 //# Correspondence concerning AIPS++ should be addressed as follows: 00021 //# Internet email: aips2-request@nrao.edu. 00022 //# Postal address: AIPS++ Project Office 00023 //# National Radio Astronomy Observatory 00024 //# 520 Edgemont Road 00025 //# Charlottesville, VA 22903-2475 USA 00026 //# 00027 //# $Id$ 00028 00029 #ifndef CASA_MMAPIO_H 00030 #define CASA_MMAPIO_H 00031 00032 //# Includes 00033 #include <casacore/casa/aips.h> 00034 #include <casacore/casa/IO/MMapfdIO.h> 00035 #include <casacore/casa/OS/RegularFile.h> 00036 00037 namespace casacore 00038 { 00039 00040 // <summary> 00041 // Memory-mapped IO on a file. 00042 // </summary> 00043 00044 // <synopsis> 00045 // Memory-mapped IO lets the OS take care of caching file segments. 00046 // This is particularly useful for the Tiled Storage Manager which keeps a 00047 // cache of tiles. When using memory-mapped IO it does not need to do that 00048 // anymore. 00049 // 00050 // On 32-bit systems its use is limited because for large files the 4 GB 00051 // memory space is insufficient. However, for 64-bit systems the memory 00052 // space is large enough to make use of it. 00053 // 00054 // In the general case there is direct access to the mapped file space. 00055 // The read and write methods copies the data into/from a buffer. 00056 // However, to avoid the copying it is possible to get a direct pointer 00057 // to the mapped data. This should be used with care, because writing to 00058 // it will cause a segmentation if the file is readonly. If the file is 00059 // writable, writing into the mapped data segment means changing the file 00060 // contents. 00061 // </synopsis> 00062 00063 class MMapIO: public MMapfdIO 00064 { 00065 public: 00066 // Open the given file and map it entirely into memory with read access. 00067 // The map has write access if the file is opened for write. 00068 explicit MMapIO (const RegularFile& regularFile, 00069 ByteIO::OpenOption = ByteIO::Old); 00070 00071 // Destructor. 00072 // It will flush and unmap the file. 00073 ~MMapIO(); 00074 00075 private: 00076 // Forbid copy constructor and assignment 00077 // <group> 00078 MMapIO (const MMapIO&); 00079 MMapIO& operator= (const MMapIO&); 00080 // </group> 00081 }; 00082 00083 } // end namespace 00084 00085 #endif