MemoryMap.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __MEMORYMAP_H
00019 #define __MEMORYMAP_H
00020 #include <sys/types.h>
00021 #include <fcntl.h>
00022
00023 #if defined(WIN32)
00024 #include <windows.h>
00025 #endif
00026
00155 class MemoryMap
00156 {
00157 #if defined(WIN32)
00158 static SYSTEM_INFO system_info;
00159 HANDLE file_handle;
00160 HANDLE map_handle;
00161 #else
00162 int fd;
00163 #endif
00164 off_t offset;
00165 size_t mapped_length;
00166 size_t total_length;
00167 size_t page_size;
00168 bool useMemoryMapFlag;
00169 public:
00170
00171 void *data;
00172
00173 MemoryMap();
00174
00175 virtual ~MemoryMap();
00176
00177 void debug_print();
00178
00179 void constructor_clear();
00180
00181 void destructor_clear();
00182
00188 virtual bool open(const char * file, int flags = O_RDONLY);
00189
00195
00196 virtual bool create(const char * file, size_t size);
00197
00204
00205 virtual bool create(size_t size);
00206
00207 bool close();
00208 void test();
00209 size_t length()
00210 {
00211 return mapped_length;
00212 }
00213
00214 char operator[](unsigned int index)
00215 {
00216 return ((char *)data)[index];
00217 };
00218 int prefetch();
00219
00220
00221
00222
00223
00224
00225 void useMemoryMap(bool flag=true)
00226 {
00227 useMemoryMapFlag = flag;
00228 }
00229 };
00230
00231 #endif