MemoryManagerMemMap.cpp
Go to the documentation of this file.
1 /* ========================================================================
2  * PROJECT: ARToolKitPlus
3  * ========================================================================
4  * This work is based on the original ARToolKit developed by
5  * Hirokazu Kato
6  * Mark Billinghurst
7  * HITLab, University of Washington, Seattle
8  * http://www.hitl.washington.edu/artoolkit/
9  *
10  * Copyright of the derived and new portions of this work
11  * (C) 2006 Graz University of Technology
12  *
13  * This framework is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This framework is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this framework; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26  *
27  * For further information please contact
28  * Dieter Schmalstieg
29  * <schmalstieg@icg.tu-graz.ac.at>
30  * Graz University of Technology,
31  * Institut for Computer Graphics and Vision,
32  * Inffeldgasse 16a, 8010 Graz, Austria.
33  * ========================================================================
34  ** @author Daniel Wagner
35  *
36  * $Id: MemoryManagerMemMap.cpp 162 2006-04-19 21:28:10Z grabner $
37  * @file
38  * ======================================================================== */
39 
40 
42 #include <assert.h>
43 
44 
45 #if defined(_MSC_VER) || defined(_WIN32_WCE)
46 
47 namespace ARToolKitPlus
48 {
49 
50 
51 MemoryManagerMemMap::MemoryManagerMemMap()
52 {
53  _didInit = false;
54 
55  lpvMem = NULL;
56  hMapObject = NULL;
57 
58  fullSize = reservedSize = 0;
59 }
60 
61 
62 MemoryManagerMemMap::~MemoryManagerMemMap()
63 {
64  deinit();
65 }
66 
67 
68 bool
69 MemoryManagerMemMap::init(size_t nNumInitialBytes, size_t nNumGrowBytes)
70 {
71  if(_didInit)
72  return false;
73 
74  fullSize = nNumInitialBytes;
75 
76  hMapObject = CreateFileMappingW(INVALID_HANDLE_VALUE, // use paging file
77  NULL, // default security attributes
78  PAGE_READWRITE, // read/write access
79  0, // size: high 32-bits
80  (DWORD)nNumInitialBytes, // size: low 32-bits
81  L"myMemMap"); // name of map object
82  if (hMapObject == NULL)
83  return false;
84 
85  lpvMem = MapViewOfFile(hMapObject, // object to map view of
86  FILE_MAP_WRITE, // read/write access
87  0, // high offset: map from
88  0, // low offset: beginning
89  0); // default: map entire file
90 
91 
92  _didInit = lpvMem != NULL;
93  return _didInit;
94 }
95 
96 
97 bool
98 MemoryManagerMemMap::deinit()
99 {
100  if(!_didInit)
101  return false;
102 
103  if(!lpvMem || !hMapObject)
104  return false;
105 
106  // Unmap shared memory from the process's address space.
107  UnmapViewOfFile(lpvMem);
108  lpvMem = NULL;
109 
110  // Close the process's handle to the file-mapping object.
111  CloseHandle(hMapObject);
112  hMapObject = NULL;
113 
114  _didInit = false;
115  return true;
116 }
117 
118 
119 bool
120 MemoryManagerMemMap::didInit()
121 {
122  return _didInit;
123 }
124 
125 
126 void*
127 MemoryManagerMemMap::getMemory(size_t nNumBytes)
128 {
129  // check if enough memory is left
130  //
131  if(reservedSize+nNumBytes > fullSize)
132  {
133  assert(false && "out of memory in MemoryManagerMemMap");
134  return NULL;
135  }
136 
137  void* newBlock = reinterpret_cast<unsigned char*>(lpvMem) + reservedSize;
138 
139  reservedSize += nNumBytes;
140  return newBlock;
141 }
142 
143 
144 void
145 MemoryManagerMemMap::releaseMemory(void* nMemoryBlock)
146 {
147  if(!_didInit)
148  return;
149 
150  assert(false && "MemoryManagerMemMap can not release memory...");
151 }
152 
153 } // namespace ARToolKitPlus
154 
155 #endif // defined(_MSC_VER) || defined(_WIN32_WCE)
This file should only be compiled when using ARToolKitPlus as a DLL.
Definition: ar.h:60
#define NULL
Definition: PocketKnife.h:38
static void init(void)


tuw_artoolkitplus
Author(s): Markus Bader
autogenerated on Sun Sep 4 2016 03:24:33