00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2008 Torus Knot Software Ltd 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 00024 You may alternatively use this source under the terms of a specific version of 00025 the OGRE Unrestricted License provided you have obtained such a license from 00026 Torus Knot Software Ltd. 00027 ----------------------------------------------------------------------------- 00028 */ 00029 00030 #ifndef __MemoryStdAlloc_H__ 00031 #define __MemoryStdAlloc_H__ 00032 00033 #include <memory> 00034 #include <limits> 00035 00036 #include "OgreAlignedAllocator.h" 00037 #include "OgreMemoryTracker.h" 00038 00039 namespace Ogre 00040 { 00041 #if OGRE_MEMORY_ALLOCATOR == OGRE_MEMORY_ALLOCATOR_STD 00042 00050 class _OgreExport StdAllocPolicy 00051 { 00052 public: 00053 static inline void* allocateBytes(size_t count, 00054 #if OGRE_MEMORY_TRACKER 00055 const char* file = 0, int line = 0, const char* func = 0 00056 #else 00057 const char* = 0, int = 0, const char* = 0 00058 #endif 00059 ) 00060 { 00061 void* ptr = malloc(count); 00062 #if OGRE_MEMORY_TRACKER 00063 // this alloc policy doesn't do pools 00064 MemoryTracker::get()._recordAlloc(ptr, count, 0, file, line, func); 00065 #endif 00066 return ptr; 00067 } 00068 00069 static inline void deallocateBytes(void* ptr) 00070 { 00071 #if OGRE_MEMORY_TRACKER 00072 MemoryTracker::get()._recordDealloc(ptr); 00073 #endif 00074 free(ptr); 00075 } 00076 00078 static inline size_t getMaxAllocationSize() 00079 { 00080 return std::numeric_limits<size_t>::max(); 00081 } 00082 private: 00083 // no instantiation 00084 StdAllocPolicy() 00085 { } 00086 }; 00087 00100 template <size_t Alignment = 0> 00101 class StdAlignedAllocPolicy 00102 { 00103 public: 00104 // compile-time check alignment is available. 00105 typedef int IsValidAlignment 00106 [Alignment <= 128 && ((Alignment & (Alignment-1)) == 0) ? +1 : -1]; 00107 00108 static inline void* allocateBytes(size_t count, 00109 #if OGRE_MEMORY_TRACKER 00110 const char* file = 0, int line = 0, const char* func = 0 00111 #else 00112 const char* = 0, int = 0, const char* = 0 00113 #endif 00114 ) 00115 { 00116 void* ptr = Alignment ? AlignedMemory::allocate(count, Alignment) 00117 : AlignedMemory::allocate(count); 00118 #if OGRE_MEMORY_TRACKER 00119 // this alloc policy doesn't do pools 00120 MemoryTracker::get()._recordAlloc(ptr, count, 0, file, line, func); 00121 #endif 00122 return ptr; 00123 } 00124 00125 static inline void deallocateBytes(void* ptr) 00126 { 00127 #if OGRE_MEMORY_TRACKER 00128 MemoryTracker::get()._recordDealloc(ptr); 00129 #endif 00130 AlignedMemory::deallocate(ptr); 00131 } 00132 00134 static inline size_t getMaxAllocationSize() 00135 { 00136 return std::numeric_limits<size_t>::max(); 00137 } 00138 private: 00139 // No instantiation 00140 StdAlignedAllocPolicy() 00141 { } 00142 }; 00143 00144 #endif 00145 00146 }// namespace Ogre 00147 00148 #endif // __MemoryStdAlloc_H__
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 27 22:02:24 2009