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 const char* file = 0, int line = 0, const char* func = 0) 00055 { 00056 void* ptr = malloc(count); 00057 #if OGRE_MEMORY_TRACKER 00058 // this alloc policy doesn't do pools 00059 MemoryTracker::get()._recordAlloc(ptr, count, 0, file, line, func); 00060 #else 00061 // avoid unused params warning 00062 count=file+line-func; 00063 #endif 00064 return ptr; 00065 } 00066 00067 static inline void deallocateBytes(void* ptr) 00068 { 00069 #if OGRE_MEMORY_TRACKER 00070 MemoryTracker::get()._recordDealloc(ptr); 00071 #endif 00072 free(ptr); 00073 } 00074 00076 static inline size_t getMaxAllocationSize() 00077 { 00078 return std::numeric_limits<size_t>::max(); 00079 } 00080 private: 00081 // no instantiation 00082 StdAllocPolicy() 00083 { } 00084 }; 00085 00098 template <size_t Alignment = 0> 00099 class StdAlignedAllocPolicy 00100 { 00101 public: 00102 // compile-time check alignment is available. 00103 typedef int IsValidAlignment 00104 [Alignment <= 128 && ((Alignment & (Alignment-1)) == 0) ? +1 : -1]; 00105 00106 static inline void* allocateBytes(size_t count, 00107 const char* file = 0, int line = 0, const char* func = 0) 00108 { 00109 void* ptr = Alignment ? AlignedMemory::allocate(count, Alignment) 00110 : AlignedMemory::allocate(count); 00111 #if OGRE_MEMORY_TRACKER 00112 // this alloc policy doesn't do pools 00113 MemoryTracker::get()._recordAlloc(ptr, count, 0, file, line, func); 00114 #else 00115 // avoid unused params warning 00116 file;line;func; 00117 #endif 00118 return ptr; 00119 } 00120 00121 static inline void deallocateBytes(void* ptr) 00122 { 00123 #if OGRE_MEMORY_TRACKER 00124 MemoryTracker::get()._recordDealloc(ptr); 00125 #endif 00126 AlignedMemory::deallocate(ptr); 00127 } 00128 00130 static inline size_t getMaxAllocationSize() 00131 { 00132 return std::numeric_limits<size_t>::max(); 00133 } 00134 private: 00135 // No instantiation 00136 StdAlignedAllocPolicy() 00137 { } 00138 }; 00139 00140 #endif 00141 00142 }// namespace Ogre 00143 00144 #endif // __MemoryStdAlloc_H__
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Tue Nov 4 11:02:30 2008