Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXMemMap.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * M e m o r y M a p p e d F i l e *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2004,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXMemMap.h,v 1.8 2006/01/22 17:58:06 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXMEMMAP_H
25 #define FXMEMMAP_H
26 
27 namespace FX {
28 
29 
30 /**
31 * A Memory Map provides a view of a file as an array of memory;
32 * this allows the file itself to be used as backing for the data
33 * and very simplified file access results.
34 * Moreover, mapped files may be shared by processes, resuling
35 * in far less "real" memory being used than would otherwise be
36 * the case.
37 */
38 class FXAPI FXMemMap {
39 private:
40  void* mapbase; // Memory base where it is mapped
41  long maplength; // Length of the map
42  long mapoffset; // Offset of the map
43  FXInputHandle handle; // Handle for the map
44  FXInputHandle file; // Handle for the file
45 private:
46  FXMemMap(const FXMemMap&);
47  FXMemMap &operator=(const FXMemMap&);
48 public:
49 
50  /// Memory map access modes
51  enum {
52  NONE = 0, /// Map is inaccessible
53  READ = 1, /// Readable
54  WRITE = 2, /// Writable
55  EXEC = 4, /// Executable (where supported)
56  TRUNC = 8 /// Truncate file to 0
57  };
58 
59  /// Share mode
60  enum {
61  PRIV = 0, /// Private
62  SHAR = 1 /// Shared
63  };
64 
65 public:
66 
67  /// Construct a memory map
68  FXMemMap();
69 
70  /// Map a view of the file; the offset must be a multiple of the page size
71  void* mapFile(const FXString& filename,long off=0,long len=-1L,FXuint access=READ,FXuint share=PRIV);
72 
73  /// Unmap the view of the file
74  void* unmap();
75 
76  /// Synchronize disk
77  void sync();
78 
79  /// Return pointer to memory area
80  void* base() const { return mapbase; }
81 
82  /// Obtain length of the map
83  long length() const { return maplength; }
84 
85  /// Obtain offset of the map
86  long offset() const { return mapoffset; }
87 
88  /// Destroy the map
89  ~FXMemMap();
90  };
91 
92 
93 }
94 
95 #endif
unsigned int FXuint
Definition: fxdefs.h:396
#define FXAPI
Definition: fxdefs.h:122
FXint FXInputHandle
Definition: fxdefs.h:468
A Memory Map provides a view of a file as an array of memory; this allows the file itself to be used ...
Definition: FXMemMap.h:38
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33

Copyright © 1997-2005 Jeroen van der Zijp