Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
00001 /******************************************************************************** 00002 * * 00003 * M e m o r y M a p p e d F i l e * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2004,2006 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXMemMap.h,v 1.8 2006/01/22 17:58:06 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXMEMMAP_H 00025 #define FXMEMMAP_H 00026 00027 namespace FX { 00028 00029 00030 /** 00031 * A Memory Map provides a view of a file as an array of memory; 00032 * this allows the file itself to be used as backing for the data 00033 * and very simplified file access results. 00034 * Moreover, mapped files may be shared by processes, resuling 00035 * in far less "real" memory being used than would otherwise be 00036 * the case. 00037 */ 00038 class FXAPI FXMemMap { 00039 private: 00040 void* mapbase; // Memory base where it is mapped 00041 long maplength; // Length of the map 00042 long mapoffset; // Offset of the map 00043 FXInputHandle handle; // Handle for the map 00044 FXInputHandle file; // Handle for the file 00045 private: 00046 FXMemMap(const FXMemMap&); 00047 FXMemMap &operator=(const FXMemMap&); 00048 public: 00049 00050 /// Memory map access modes 00051 enum { 00052 NONE = 0, /// Map is inaccessible 00053 READ = 1, /// Readable 00054 WRITE = 2, /// Writable 00055 EXEC = 4, /// Executable (where supported) 00056 TRUNC = 8 /// Truncate file to 0 00057 }; 00058 00059 /// Share mode 00060 enum { 00061 PRIV = 0, /// Private 00062 SHAR = 1 /// Shared 00063 }; 00064 00065 public: 00066 00067 /// Construct a memory map 00068 FXMemMap(); 00069 00070 /// Map a view of the file; the offset must be a multiple of the page size 00071 void* mapFile(const FXString& filename,long off=0,long len=-1L,FXuint access=READ,FXuint share=PRIV); 00072 00073 /// Unmap the view of the file 00074 void* unmap(); 00075 00076 /// Synchronize disk 00077 void sync(); 00078 00079 /// Return pointer to memory area 00080 void* base() const { return mapbase; } 00081 00082 /// Obtain length of the map 00083 long length() const { return maplength; } 00084 00085 /// Obtain offset of the map 00086 long offset() const { return mapoffset; } 00087 00088 /// Destroy the map 00089 ~FXMemMap(); 00090 }; 00091 00092 00093 } 00094 00095 #endif
Copyright © 1997-2005 Jeroen van der Zijp |