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 __MemoryNedAlloc_H__ 00031 #define __MemoryNedAlloc_H__ 00032 00033 #include "OgreMemoryTracker.h" 00034 00035 // This is an example of using a non-standard allocator with Ogre 00036 // Note, you need nedmalloc available on your build path to support this 00037 // See http://nedprod.com/programs/portable/nedmalloc/index.html 00038 00039 #include <nedmalloc.h> 00040 00041 namespace Ogre 00042 { 00043 00052 class _OgreExport NedAllocPolicy 00053 { 00054 public: 00055 static inline void* allocateBytes(size_t count, 00056 const char* file = 0, int line = 0, const char* func = 0) 00057 { 00058 void* ptr = nedalloc::nedmalloc(count); 00059 #if OGRE_MEMORY_TRACKER 00060 // this alloc policy doesn't do pools (yet, ned can do it) 00061 MemoryTracker::get()._recordAlloc(ptr, count, 0, file, line, func); 00062 #else 00063 // avoid unused params warning 00064 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 nedalloc::nedfree(ptr); 00075 } 00076 00078 static inline size_t getMaxAllocationSize() 00079 { 00080 return std::numeric_limits<size_t>::max(); 00081 } 00082 00083 private: 00084 // No instantiation 00085 NedAllocPolicy() 00086 { } 00087 }; 00088 00101 template <size_t Alignment = 0> 00102 class NedAlignedAllocPolicy 00103 { 00104 public: 00105 // compile-time check alignment is available. 00106 typedef int IsValidAlignment 00107 [Alignment <= 128 && ((Alignment & (Alignment-1)) == 0) ? +1 : -1]; 00108 00109 static inline void* allocateBytes(size_t count, 00110 const char* file = 0, int line = 0, const char* func = 0) 00111 { 00112 // default to platform SIMD alignment if none specified 00113 void* ptr = Alignment ? nedalloc::nedmemalign(Alignment, count) 00114 : nedalloc::nedmemalign(OGRE_SIMD_ALIGNMENT, count); 00115 #if OGRE_MEMORY_TRACKER 00116 // this alloc policy doesn't do pools (yet, ned can do it) 00117 MemoryTracker::get()._recordAlloc(ptr, count, 0, file, line, func); 00118 #else 00119 // avoid unused params warning 00120 file;line;func; 00121 #endif 00122 return ptr; 00123 } 00124 00125 static inline void deallocateBytes(void* ptr) 00126 { 00127 #if OGRE_MEMORY_TRACKER 00128 // this alloc policy doesn't do pools (yet, ned can do it) 00129 MemoryTracker::get()._recordDealloc(ptr); 00130 #endif 00131 nedalloc::nedfree(ptr); 00132 } 00133 00135 static inline size_t getMaxAllocationSize() 00136 { 00137 return std::numeric_limits<size_t>::max(); 00138 } 00139 private: 00140 // no instantiation allowed 00141 NedAlignedAllocPolicy() 00142 { } 00143 }; 00144 00145 // you might also want to declare policies based on ned's pooled allocators 00146 // if you want - that is lefts as an exercise for the user 00147 00148 00149 00150 }// namespace Ogre 00151 #endif // __MemoryNedAlloc_H__
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Aug 28 20:53:49 2008