Bullet Collision Detection & Physics Library
btAlignedAllocator.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 #ifndef BT_ALIGNED_ALLOCATOR
17 #define BT_ALIGNED_ALLOCATOR
18 
22 
23 #include "btScalar.h"
24 
25 
29 #ifdef BT_DEBUG_MEMORY_ALLOCATIONS
30 
31 int btDumpMemoryLeaks();
32 
33 #define btAlignedAlloc(a,b) \
34  btAlignedAllocInternal(a,b,__LINE__,__FILE__)
35 
36 #define btAlignedFree(ptr) \
37  btAlignedFreeInternal(ptr,__LINE__,__FILE__)
38 
39 void* btAlignedAllocInternal (size_t size, int alignment,int line,char* filename);
40 
41 void btAlignedFreeInternal (void* ptr,int line,char* filename);
42 
43 #else
44  void* btAlignedAllocInternal (size_t size, int alignment);
45  void btAlignedFreeInternal (void* ptr);
46 
47  #define btAlignedAlloc(size,alignment) btAlignedAllocInternal(size,alignment)
48  #define btAlignedFree(ptr) btAlignedFreeInternal(ptr)
49 
50 #endif
51 typedef int size_type;
52 
53 typedef void *(btAlignedAllocFunc)(size_t size, int alignment);
54 typedef void (btAlignedFreeFunc)(void *memblock);
55 typedef void *(btAllocFunc)(size_t size);
56 typedef void (btFreeFunc)(void *memblock);
57 
59 void btAlignedAllocSetCustom(btAllocFunc *allocFunc, btFreeFunc *freeFunc);
62 
63 
66 template < typename T , unsigned Alignment >
68 
70 
71 public:
72 
73  //just going down a list:
75  /*
76  btAlignedAllocator( const self_type & ) {}
77  */
78 
79  template < typename Other >
81 
82  typedef const T* const_pointer;
83  typedef const T& const_reference;
84  typedef T* pointer;
85  typedef T& reference;
86  typedef T value_type;
87 
88  pointer address ( reference ref ) const { return &ref; }
89  const_pointer address ( const_reference ref ) const { return &ref; }
90  pointer allocate ( size_type n , const_pointer * hint = 0 ) {
91  (void)hint;
92  return reinterpret_cast< pointer >(btAlignedAlloc( sizeof(value_type) * n , Alignment ));
93  }
94  void construct ( pointer ptr , const value_type & value ) { new (ptr) value_type( value ); }
95  void deallocate( pointer ptr ) {
96  btAlignedFree( reinterpret_cast< void * >( ptr ) );
97  }
98  void destroy ( pointer ptr ) { ptr->~value_type(); }
99 
100 
101  template < typename O > struct rebind {
103  };
104  template < typename O >
105  self_type & operator=( const btAlignedAllocator< O , Alignment > & ) { return *this; }
106 
107  friend bool operator==( const self_type & , const self_type & ) { return true; }
108 };
109 
110 
111 
112 #endif //BT_ALIGNED_ALLOCATOR
113 
btAlignedAllocator< T, Alignment > self_type
void deallocate(pointer ptr)
void destroy(pointer ptr)
btAlignedAllocator(const btAlignedAllocator< Other, Alignment > &)
friend bool operator==(const self_type &, const self_type &)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
void btAlignedAllocSetCustom(btAllocFunc *allocFunc, btFreeFunc *freeFunc)
The developer can let all Bullet memory allocations go through a custom memory allocator, using btAlignedAllocSetCustom.
const_pointer address(const_reference ref) const
void * btAlignedAllocInternal(size_t size, int alignment)
we probably replace this with our own aligned memory allocator so we replace _aligned_malloc and _ali...
void btAlignedFreeInternal(void *ptr)
int size_type
void( btFreeFunc)(void *memblock)
void *( btAlignedAllocFunc)(size_t size, int alignment)
self_type & operator=(const btAlignedAllocator< O, Alignment > &)
void( btAlignedFreeFunc)(void *memblock)
#define btAlignedFree(ptr)
void *( btAllocFunc)(size_t size)
void btAlignedAllocSetCustomAligned(btAlignedAllocFunc *allocFunc, btAlignedFreeFunc *freeFunc)
If the developer has already an custom aligned allocator, then btAlignedAllocSetCustomAligned can be ...
btAlignedAllocator< O, Alignment > other
void construct(pointer ptr, const value_type &value)
The btAlignedAllocator is a portable class for aligned memory allocations.
#define btAlignedAlloc(size, alignment)
pointer address(reference ref) const
pointer allocate(size_type n, const_pointer *hint=0)