casa
$Rev:20696$
|
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: MMapIO.h 20859 2010-02-03 13:14:15Z gervandiepen $ 00028 00029 #ifndef CASA_MMAPIO_H 00030 #define CASA_MMAPIO_H 00031 00032 //# Includes 00033 #include <casa/IO/MMapfdIO.h> 00034 #include <casa/OS/RegularFile.h> 00035 00036 namespace casa 00037 { 00038 00039 // <summary> 00040 // Memory-mapped IO on a file. 00041 // </summary> 00042 00043 // <synopsis> 00044 // Memory-mapped IO lets the OS take care of caching file segments. 00045 // This is particularly useful for the Tiled Storage Manager which keeps a 00046 // cache of tiles. When using memory-mapped IO it does not need to do that 00047 // anymore. 00048 // 00049 // On 32-bit systems its use is limited because for large files the 4 GB 00050 // memory space is insufficient. However, for 64-bit systems the memory 00051 // space is large enough to make use of it. 00052 // 00053 // In the general case there is direct access to the mapped file space. 00054 // The read and write methods copies the data into/from a buffer. 00055 // However, to avoid the copying it is possible to get a direct pointer 00056 // to the mapped data. This should be used with care, because writing to 00057 // it will cause a segmentation if the file is readonly. If the file is 00058 // writable, writing into the mapped data segment means changing the file 00059 // contents. 00060 // </synopsis> 00061 00062 class MMapIO: public MMapfdIO 00063 { 00064 public: 00065 // Open the given file and map it entirely into memory with read access. 00066 // The map has write access if the file is opened for write. 00067 explicit MMapIO (const RegularFile& regularFile, 00068 ByteIO::OpenOption = ByteIO::Old); 00069 00070 // Destructor. 00071 // It will flush and unmap the file. 00072 ~MMapIO(); 00073 00074 private: 00075 // Forbid copy constructor and assignment 00076 // <group> 00077 MMapIO (const MMapIO&); 00078 MMapIO& operator= (const MMapIO&); 00079 // </group> 00080 }; 00081 00082 } // end namespace 00083 00084 #endif