My Project: dynamics.mod/NewtonDynamics/source/ampPhysics/dgAmpAllocator.h Source File

My Project

dgAmpAllocator.h
Go to the documentation of this file.
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21
22 #ifndef _DG_AMP_ALLOCATOR_H_
23 #define _DG_AMP_ALLOCATOR_H_
24
25 #include "dgAMP.h"
26
27 template <typename T>
28 class dgAmpAllocator: public std::allocator<T>
29 {
30 public:
31 typedef size_t size_type;
32 typedef T* pointer;
33 typedef const T* const_pointer;
34
35 template<typename _Tp1>
36 struct rebind
37 {
38 typedef dgAmpAllocator<_Tp1> other;
39 };
40
41 pointer allocate(size_type n, const void *hint=0)
42 {
43 return (pointer)m_allocator->Malloc(dgInt32 (n * sizeof (T)));
44 }
45
46 void deallocate(pointer p, size_type n)
47 {
48 m_allocator->Free(p);
49 }
50
51 dgAmpAllocator(dgMemoryAllocator* const allocator) throw()
52 :std::allocator<T>()
53 ,m_allocator(allocator)
54 {
55 }
56
57 dgAmpAllocator() throw()
58 :std::allocator<T>()
59 ,m_allocator(NULL)
60 {
61 dgAssert (0);
62 }
63
64 dgAmpAllocator(const dgAmpAllocator &a) throw()
65 :std::allocator<T>(a)
66 ,m_allocator(a.m_allocator)
67 {
68 }
69
70 template <class U>
71 dgAmpAllocator(const dgAmpAllocator<U> &a) throw()
72 :std::allocator<T>(a)
73 ,m_allocator(a.m_allocator)
74 {
75 }
76
77 ~dgAmpAllocator() throw()
78 {
79 }
80
81 dgMemoryAllocator* m_allocator;
82 };
83
84
85 #endif
dgAmpAllocator::allocate
pointer allocate(size_type n, const void *hint=0)
Definition: dgAmpAllocator.h:41
dgAmpAllocator::dgAmpAllocator
dgAmpAllocator(const dgAmpAllocator< U > &a)
Definition: dgAmpAllocator.h:71
dgAmpAllocator::m_allocator
dgMemoryAllocator * m_allocator
Definition: dgAmpAllocator.h:81
dgAmpAllocator::dgAmpAllocator
dgAmpAllocator(const dgAmpAllocator &a)
Definition: dgAmpAllocator.h:64
dgAmpAllocator::~dgAmpAllocator
~dgAmpAllocator()
Definition: dgAmpAllocator.h:77
dgAssert
#define dgAssert(x)
Definition: dgTypes.h:158
dgInt32
int dgInt32
Definition: dgTypes.h:218
dgMemoryAllocator::Malloc
void * Malloc(dgInt32 memsize)
Definition: dgMemory.cpp:172
dgAmpAllocator::const_pointer
const T * const_pointer
Definition: dgAmpAllocator.h:33
dgAmpAllocator::dgAmpAllocator
dgAmpAllocator(dgMemoryAllocator *const allocator)
Definition: dgAmpAllocator.h:51
dgMemoryAllocator::Free
void Free(void *const retPtr)
Definition: dgMemory.cpp:245
dgAmpAllocator
Definition: dgAmpAllocator.h:28
dgAmpAllocator::rebind::other
dgAmpAllocator< _Tp1 > other
Definition: dgAmpAllocator.h:38
dgAmpAllocator::pointer
T * pointer
Definition: dgAmpAllocator.h:32
dgAmpAllocator::rebind
Definition: dgAmpAllocator.h:36
dgAMP.h
dgAmpAllocator::deallocate
void deallocate(pointer p, size_type n)
Definition: dgAmpAllocator.h:46
dgMemoryAllocator
Definition: dgMemory.h:73
dgAmpAllocator::size_type
size_t size_type
Definition: dgAmpAllocator.h:31
dgAmpAllocator::dgAmpAllocator
dgAmpAllocator()
Definition: dgAmpAllocator.h:57