OgreMemoryNedAlloc.h

Go to the documentation of this file.
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 #if OGRE_MEMORY_ALLOCATOR == OGRE_MEMORY_ALLOCATOR_NED
00034 
00035 namespace Ogre
00036 {
00039     class _OgreExport NedAllocImpl
00040     {
00041     public:
00042         static void* allocBytes(size_t count, 
00043             const char* file, int line, const char* func);
00044         static void deallocBytes(void* ptr);
00045         static void* allocBytesAligned(size_t align, size_t count, 
00046             const char* file, int line, const char* func);
00047         static void deallocBytesAligned(size_t align, void* ptr);
00048 
00049     };
00050 
00059     class _OgreExport NedAllocPolicy
00060     {
00061     public:
00062         static inline void* allocateBytes(size_t count, 
00063             const char* file = 0, int line = 0, const char* func = 0)
00064         {
00065             return NedAllocImpl::allocBytes(count, file, line, func);
00066         }
00067         static inline void deallocateBytes(void* ptr)
00068         {
00069             NedAllocImpl::deallocBytes(ptr);
00070         }
00071 
00072     private:
00073         // No instantiation
00074         NedAllocPolicy()
00075         { }
00076     };
00077 
00078 
00091     template <size_t Alignment = 0>
00092     class NedAlignedAllocPolicy
00093     {
00094     public:
00095         // compile-time check alignment is available.
00096         typedef int IsValidAlignment
00097             [Alignment <= 128 && ((Alignment & (Alignment-1)) == 0) ? +1 : -1];
00098 
00099         static inline void* allocateBytes(size_t count, 
00100             const char* file = 0, int line = 0, const char* func = 0)
00101         {
00102             return NedAllocImpl::allocBytesAligned(Alignment, count, file, line, func);
00103         }
00104 
00105         static inline void deallocateBytes(void* ptr)
00106         {
00107             NedAllocImpl::deallocBytesAligned(Alignment, ptr);
00108         }
00109 
00111         static inline size_t getMaxAllocationSize()
00112         {
00113             return std::numeric_limits<size_t>::max();
00114         }
00115     private:
00116         // no instantiation allowed
00117         NedAlignedAllocPolicy()
00118         { }
00119     };
00120 
00121     // you might also want to declare policies based on ned's pooled allocators
00122     // if you want - that is lefts as an exercise for the user
00123 
00124 
00125 
00126 }// namespace Ogre
00127 
00128 #endif 
00129 
00130 #endif // __MemoryNedAlloc_H__
00131 

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 27 22:02:24 2009