Game Develop C++ Platform: btAlignedAllocator.h Source File

| Game Develop C++ Platform Platform for developing native games based on OpenGL and SFML with Game Develop

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
btAlignedAllocator.h
1 #if defined(GD_IDE_ONLY) || defined(DEBUG) || defined(DEV)
2 /*
3 Bullet Continuous Collision Detection and Physics Library
4 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
5
6 This software is provided 'as-is', without any express or implied warranty.
7 In no event will the authors be held liable for any damages arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it freely,
10 subject to the following restrictions:
11
12 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.
13 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
14 3. This notice may not be removed or altered from any source distribution.
15 */
16
17 #ifndef BT_ALIGNED_ALLOCATOR
18 #define BT_ALIGNED_ALLOCATOR
19
23
24 #include "GDCpp/btScalar.h"
25 //#define BT_DEBUG_MEMORY_ALLOCATIONS 1
26 #ifdef BT_DEBUG_MEMORY_ALLOCATIONS
27
28 #define btAlignedAlloc(a,b) \
29 btAlignedAllocInternal(a,b,__LINE__,__FILE__)
30
31 #define btAlignedFree(ptr) \
32 btAlignedFreeInternal(ptr,__LINE__,__FILE__)
33
34 void* btAlignedAllocInternal (size_t size, int alignment,int line,char* filename);
35
36 void btAlignedFreeInternal (void* ptr,int line,char* filename);
37
38 #else
39 void* btAlignedAllocInternal (size_t size, int alignment);
40 void btAlignedFreeInternal (void* ptr);
41
42 #define btAlignedAlloc(size,alignment) btAlignedAllocInternal(size,alignment)
43 #define btAlignedFree(ptr) btAlignedFreeInternal(ptr)
44
45 #endif
46 typedef int size_type;
47
48 typedef void *(btAlignedAllocFunc)(size_t size, int alignment);
49 typedef void (btAlignedFreeFunc)(void *memblock);
50 typedef void *(btAllocFunc)(size_t size);
51 typedef void (btFreeFunc)(void *memblock);
52
54 void btAlignedAllocSetCustom(btAllocFunc *allocFunc, btFreeFunc *freeFunc);
56 void btAlignedAllocSetCustomAligned(btAlignedAllocFunc *allocFunc, btAlignedFreeFunc *freeFunc);
57
58
61 template < typename T , unsigned Alignment >
62 class btAlignedAllocator {
63
64 typedef btAlignedAllocator< T , Alignment > self_type;
65
66 public:
67
68 //just going down a list:
69 btAlignedAllocator() {}
70 /*
71 btAlignedAllocator( const self_type & ) {}
72 */
73
74 template < typename Other >
75 btAlignedAllocator( const btAlignedAllocator< Other , Alignment > & ) {}
76
77 typedef const T* const_pointer;
78 typedef const T& const_reference;
79 typedef T* pointer;
80 typedef T& reference;
81 typedef T value_type;
82
83 pointer address ( reference ref ) const { return &ref; }
84 const_pointer address ( const_reference ref ) const { return &ref; }
85 pointer allocate ( size_type n , const_pointer * hint = 0 ) {
86 (void)hint;
87 return reinterpret_cast< pointer >(btAlignedAlloc( sizeof(value_type) * n , Alignment ));
88 }
89 void construct ( pointer ptr , const value_type & value ) { new (ptr) value_type( value ); }
90 void deallocate( pointer ptr ) {
91 btAlignedFree( reinterpret_cast< void * >( ptr ) );
92 }
93 void destroy ( pointer ptr ) { ptr->~value_type(); }
94
95
96 template < typename O > struct rebind {
97 typedef btAlignedAllocator< O , Alignment > other;
98 };
99 template < typename O >
100 self_type & operator=( const btAlignedAllocator< O , Alignment > & ) { return *this; }
101
102 friend bool operator==( const self_type & , const self_type & ) { return true; }
103 };
104 #endif //BT_ALIGNED_ALLOCATOR
105
106 #endif
107