MemoryManagerMemMap.cpp
Go to the documentation of this file.
00001 /* ========================================================================
00002  * PROJECT: ARToolKitPlus
00003  * ========================================================================
00004  * This work is based on the original ARToolKit developed by
00005  *   Hirokazu Kato
00006  *   Mark Billinghurst
00007  *   HITLab, University of Washington, Seattle
00008  * http://www.hitl.washington.edu/artoolkit/
00009  *
00010  * Copyright of the derived and new portions of this work
00011  *     (C) 2006 Graz University of Technology
00012  *
00013  * This framework is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This framework is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this framework; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  *
00027  * For further information please contact 
00028  *   Dieter Schmalstieg
00029  *   <schmalstieg@icg.tu-graz.ac.at>
00030  *   Graz University of Technology, 
00031  *   Institut for Computer Graphics and Vision,
00032  *   Inffeldgasse 16a, 8010 Graz, Austria.
00033  * ========================================================================
00034  ** @author   Daniel Wagner
00035  *
00036  * $Id: MemoryManagerMemMap.cpp 162 2006-04-19 21:28:10Z grabner $
00037  * @file
00038  * ======================================================================== */
00039 
00040 
00041 #include <ARToolKitPlus/MemoryManagerMemMap.h>
00042 #include <assert.h>
00043 
00044 
00045 #if defined(_MSC_VER) || defined(_WIN32_WCE)
00046 
00047 namespace ARToolKitPlus
00048 {
00049 
00050 
00051 MemoryManagerMemMap::MemoryManagerMemMap()
00052 {
00053         _didInit = false;
00054 
00055         lpvMem = NULL;
00056         hMapObject = NULL;
00057 
00058         fullSize = reservedSize = 0;
00059 }
00060 
00061 
00062 MemoryManagerMemMap::~MemoryManagerMemMap()
00063 {
00064         deinit();
00065 }
00066 
00067 
00068 bool
00069 MemoryManagerMemMap::init(size_t nNumInitialBytes, size_t nNumGrowBytes)
00070 {
00071         if(_didInit)
00072                 return false;
00073 
00074         fullSize = nNumInitialBytes;
00075 
00076         hMapObject = CreateFileMappingW(INVALID_HANDLE_VALUE,           // use paging file
00077                                                                         NULL,                                           // default security attributes
00078                                                                         PAGE_READWRITE,                         // read/write access
00079                                                                         0,                                                      // size: high 32-bits
00080                                                                         (DWORD)nNumInitialBytes,        // size: low 32-bits
00081                                                                         L"myMemMap");                           // name of map object
00082         if (hMapObject == NULL) 
00083                 return false;
00084  
00085         lpvMem = MapViewOfFile(hMapObject,     // object to map view of
00086                                                    FILE_MAP_WRITE, // read/write access
00087                                                    0,              // high offset:  map from
00088                                                    0,              // low offset:   beginning
00089                                                    0);             // default: map entire file
00090 
00091 
00092         _didInit = lpvMem != NULL;
00093         return _didInit;
00094 }
00095 
00096 
00097 bool
00098 MemoryManagerMemMap::deinit()
00099 {
00100         if(!_didInit)
00101                 return false;
00102 
00103         if(!lpvMem || !hMapObject)
00104                 return false;
00105 
00106         // Unmap shared memory from the process's address space.
00107         UnmapViewOfFile(lpvMem); 
00108         lpvMem = NULL;
00109  
00110         // Close the process's handle to the file-mapping object.
00111         CloseHandle(hMapObject); 
00112         hMapObject = NULL;
00113 
00114         _didInit = false;
00115         return true;
00116 }
00117 
00118 
00119 bool
00120 MemoryManagerMemMap::didInit()
00121 {
00122         return _didInit;
00123 }
00124 
00125 
00126 void*
00127 MemoryManagerMemMap::getMemory(size_t nNumBytes)
00128 {
00129         // check if enough memory is left
00130         //
00131         if(reservedSize+nNumBytes > fullSize)
00132         {
00133                 assert(false && "out of memory in MemoryManagerMemMap");
00134                 return NULL;
00135         }
00136 
00137         void* newBlock = reinterpret_cast<unsigned char*>(lpvMem) + reservedSize;
00138 
00139         reservedSize += nNumBytes;
00140         return newBlock;
00141 }
00142 
00143 
00144 void
00145 MemoryManagerMemMap::releaseMemory(void* nMemoryBlock)
00146 {
00147         if(!_didInit)
00148                 return;
00149 
00150         assert(false && "MemoryManagerMemMap can not release memory...");
00151 }
00152 
00153 }  // namespace ARToolKitPlus
00154 
00155 #endif  // defined(_MSC_VER) || defined(_WIN32_WCE)


v4r_artoolkitplus
Author(s): Markus Bader
autogenerated on Wed Aug 26 2015 16:41:53