Blender V2.61 - r43446
|
00001 /* 00002 Bullet Continuous Collision Detection and Physics Library 00003 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ 00004 00005 This software is provided 'as-is', without any express or implied warranty. 00006 In no event will the authors be held liable for any damages arising from the use of this software. 00007 Permission is granted to anyone to use this software for any purpose, 00008 including commercial applications, and to alter it and redistribute it freely, 00009 subject to the following restrictions: 00010 00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 00013 3. This notice may not be removed or altered from any source distribution. 00014 */ 00015 00016 #ifndef BT_ALIGNED_ALLOCATOR 00017 #define BT_ALIGNED_ALLOCATOR 00018 00022 00023 #include "btScalar.h" 00024 //#define BT_DEBUG_MEMORY_ALLOCATIONS 1 00025 #ifdef BT_DEBUG_MEMORY_ALLOCATIONS 00026 00027 #define btAlignedAlloc(a,b) \ 00028 btAlignedAllocInternal(a,b,__LINE__,__FILE__) 00029 00030 #define btAlignedFree(ptr) \ 00031 btAlignedFreeInternal(ptr,__LINE__,__FILE__) 00032 00033 void* btAlignedAllocInternal (size_t size, int alignment,int line,char* filename); 00034 00035 void btAlignedFreeInternal (void* ptr,int line,char* filename); 00036 00037 #else 00038 void* btAlignedAllocInternal (size_t size, int alignment); 00039 void btAlignedFreeInternal (void* ptr); 00040 00041 #define btAlignedAlloc(size,alignment) btAlignedAllocInternal(size,alignment) 00042 #define btAlignedFree(ptr) btAlignedFreeInternal(ptr) 00043 00044 #endif 00045 typedef int size_type; 00046 00047 typedef void *(btAlignedAllocFunc)(size_t size, int alignment); 00048 typedef void (btAlignedFreeFunc)(void *memblock); 00049 typedef void *(btAllocFunc)(size_t size); 00050 typedef void (btFreeFunc)(void *memblock); 00051 00053 void btAlignedAllocSetCustom(btAllocFunc *allocFunc, btFreeFunc *freeFunc); 00055 void btAlignedAllocSetCustomAligned(btAlignedAllocFunc *allocFunc, btAlignedFreeFunc *freeFunc); 00056 00057 00060 template < typename T , unsigned Alignment > 00061 class btAlignedAllocator { 00062 00063 typedef btAlignedAllocator< T , Alignment > self_type; 00064 00065 public: 00066 00067 //just going down a list: 00068 btAlignedAllocator() {} 00069 /* 00070 btAlignedAllocator( const self_type & ) {} 00071 */ 00072 00073 template < typename Other > 00074 btAlignedAllocator( const btAlignedAllocator< Other , Alignment > & ) {} 00075 00076 typedef const T* const_pointer; 00077 typedef const T& const_reference; 00078 typedef T* pointer; 00079 typedef T& reference; 00080 typedef T value_type; 00081 00082 pointer address ( reference ref ) const { return &ref; } 00083 const_pointer address ( const_reference ref ) const { return &ref; } 00084 pointer allocate ( size_type n , const_pointer * hint = 0 ) { 00085 (void)hint; 00086 return reinterpret_cast< pointer >(btAlignedAlloc( sizeof(value_type) * n , Alignment )); 00087 } 00088 void construct ( pointer ptr , const value_type & value ) { new (ptr) value_type( value ); } 00089 void deallocate( pointer ptr ) { 00090 btAlignedFree( reinterpret_cast< void * >( ptr ) ); 00091 } 00092 void destroy ( pointer ptr ) { ptr->~value_type(); } 00093 00094 00095 template < typename O > struct rebind { 00096 typedef btAlignedAllocator< O , Alignment > other; 00097 }; 00098 template < typename O > 00099 self_type & operator=( const btAlignedAllocator< O , Alignment > & ) { return *this; } 00100 00101 friend bool operator==( const self_type & , const self_type & ) { return true; } 00102 }; 00103 00104 00105 00106 #endif //BT_ALIGNED_ALLOCATOR 00107