diff options
Diffstat (limited to 'libraries/irrlicht-1.8/include/irrAllocator.h')
-rw-r--r-- | libraries/irrlicht-1.8/include/irrAllocator.h | 248 |
1 files changed, 124 insertions, 124 deletions
diff --git a/libraries/irrlicht-1.8/include/irrAllocator.h b/libraries/irrlicht-1.8/include/irrAllocator.h index 648c410..8a80359 100644 --- a/libraries/irrlicht-1.8/include/irrAllocator.h +++ b/libraries/irrlicht-1.8/include/irrAllocator.h | |||
@@ -1,124 +1,124 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt |
2 | // This file is part of the "Irrlicht Engine" and the "irrXML" project. | 2 | // This file is part of the "Irrlicht Engine" and the "irrXML" project. |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h and irrXML.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h and irrXML.h |
4 | 4 | ||
5 | #ifndef __IRR_ALLOCATOR_H_INCLUDED__ | 5 | #ifndef __IRR_ALLOCATOR_H_INCLUDED__ |
6 | #define __IRR_ALLOCATOR_H_INCLUDED__ | 6 | #define __IRR_ALLOCATOR_H_INCLUDED__ |
7 | 7 | ||
8 | #include "irrTypes.h" | 8 | #include "irrTypes.h" |
9 | #include <new> | 9 | #include <new> |
10 | // necessary for older compilers | 10 | // necessary for older compilers |
11 | #include <memory.h> | 11 | #include <memory.h> |
12 | 12 | ||
13 | namespace irr | 13 | namespace irr |
14 | { | 14 | { |
15 | namespace core | 15 | namespace core |
16 | { | 16 | { |
17 | 17 | ||
18 | #ifdef DEBUG_CLIENTBLOCK | 18 | #ifdef DEBUG_CLIENTBLOCK |
19 | #undef DEBUG_CLIENTBLOCK | 19 | #undef DEBUG_CLIENTBLOCK |
20 | #define DEBUG_CLIENTBLOCK new | 20 | #define DEBUG_CLIENTBLOCK new |
21 | #endif | 21 | #endif |
22 | 22 | ||
23 | //! Very simple allocator implementation, containers using it can be used across dll boundaries | 23 | //! Very simple allocator implementation, containers using it can be used across dll boundaries |
24 | template<typename T> | 24 | template<typename T> |
25 | class irrAllocator | 25 | class irrAllocator |
26 | { | 26 | { |
27 | public: | 27 | public: |
28 | 28 | ||
29 | //! Destructor | 29 | //! Destructor |
30 | virtual ~irrAllocator() {} | 30 | virtual ~irrAllocator() {} |
31 | 31 | ||
32 | //! Allocate memory for an array of objects | 32 | //! Allocate memory for an array of objects |
33 | T* allocate(size_t cnt) | 33 | T* allocate(size_t cnt) |
34 | { | 34 | { |
35 | return (T*)internal_new(cnt* sizeof(T)); | 35 | return (T*)internal_new(cnt* sizeof(T)); |
36 | } | 36 | } |
37 | 37 | ||
38 | //! Deallocate memory for an array of objects | 38 | //! Deallocate memory for an array of objects |
39 | void deallocate(T* ptr) | 39 | void deallocate(T* ptr) |
40 | { | 40 | { |
41 | internal_delete(ptr); | 41 | internal_delete(ptr); |
42 | } | 42 | } |
43 | 43 | ||
44 | //! Construct an element | 44 | //! Construct an element |
45 | void construct(T* ptr, const T&e) | 45 | void construct(T* ptr, const T&e) |
46 | { | 46 | { |
47 | new ((void*)ptr) T(e); | 47 | new ((void*)ptr) T(e); |
48 | } | 48 | } |
49 | 49 | ||
50 | //! Destruct an element | 50 | //! Destruct an element |
51 | void destruct(T* ptr) | 51 | void destruct(T* ptr) |
52 | { | 52 | { |
53 | ptr->~T(); | 53 | ptr->~T(); |
54 | } | 54 | } |
55 | 55 | ||
56 | protected: | 56 | protected: |
57 | 57 | ||
58 | virtual void* internal_new(size_t cnt) | 58 | virtual void* internal_new(size_t cnt) |
59 | { | 59 | { |
60 | return operator new(cnt); | 60 | return operator new(cnt); |
61 | } | 61 | } |
62 | 62 | ||
63 | virtual void internal_delete(void* ptr) | 63 | virtual void internal_delete(void* ptr) |
64 | { | 64 | { |
65 | operator delete(ptr); | 65 | operator delete(ptr); |
66 | } | 66 | } |
67 | 67 | ||
68 | }; | 68 | }; |
69 | 69 | ||
70 | 70 | ||
71 | //! Fast allocator, only to be used in containers inside the same memory heap. | 71 | //! Fast allocator, only to be used in containers inside the same memory heap. |
72 | /** Containers using it are NOT able to be used it across dll boundaries. Use this | 72 | /** Containers using it are NOT able to be used it across dll boundaries. Use this |
73 | when using in an internal class or function or when compiled into a static lib */ | 73 | when using in an internal class or function or when compiled into a static lib */ |
74 | template<typename T> | 74 | template<typename T> |
75 | class irrAllocatorFast | 75 | class irrAllocatorFast |
76 | { | 76 | { |
77 | public: | 77 | public: |
78 | 78 | ||
79 | //! Allocate memory for an array of objects | 79 | //! Allocate memory for an array of objects |
80 | T* allocate(size_t cnt) | 80 | T* allocate(size_t cnt) |
81 | { | 81 | { |
82 | return (T*)operator new(cnt* sizeof(T)); | 82 | return (T*)operator new(cnt* sizeof(T)); |
83 | } | 83 | } |
84 | 84 | ||
85 | //! Deallocate memory for an array of objects | 85 | //! Deallocate memory for an array of objects |
86 | void deallocate(T* ptr) | 86 | void deallocate(T* ptr) |
87 | { | 87 | { |
88 | operator delete(ptr); | 88 | operator delete(ptr); |
89 | } | 89 | } |
90 | 90 | ||
91 | //! Construct an element | 91 | //! Construct an element |
92 | void construct(T* ptr, const T&e) | 92 | void construct(T* ptr, const T&e) |
93 | { | 93 | { |
94 | new ((void*)ptr) T(e); | 94 | new ((void*)ptr) T(e); |
95 | } | 95 | } |
96 | 96 | ||
97 | //! Destruct an element | 97 | //! Destruct an element |
98 | void destruct(T* ptr) | 98 | void destruct(T* ptr) |
99 | { | 99 | { |
100 | ptr->~T(); | 100 | ptr->~T(); |
101 | } | 101 | } |
102 | }; | 102 | }; |
103 | 103 | ||
104 | 104 | ||
105 | 105 | ||
106 | #ifdef DEBUG_CLIENTBLOCK | 106 | #ifdef DEBUG_CLIENTBLOCK |
107 | #undef DEBUG_CLIENTBLOCK | 107 | #undef DEBUG_CLIENTBLOCK |
108 | #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) | 108 | #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) |
109 | #endif | 109 | #endif |
110 | 110 | ||
111 | //! defines an allocation strategy | 111 | //! defines an allocation strategy |
112 | enum eAllocStrategy | 112 | enum eAllocStrategy |
113 | { | 113 | { |
114 | ALLOC_STRATEGY_SAFE = 0, | 114 | ALLOC_STRATEGY_SAFE = 0, |
115 | ALLOC_STRATEGY_DOUBLE = 1, | 115 | ALLOC_STRATEGY_DOUBLE = 1, |
116 | ALLOC_STRATEGY_SQRT = 2 | 116 | ALLOC_STRATEGY_SQRT = 2 |
117 | }; | 117 | }; |
118 | 118 | ||
119 | 119 | ||
120 | } // end namespace core | 120 | } // end namespace core |
121 | } // end namespace irr | 121 | } // end namespace irr |
122 | 122 | ||
123 | #endif | 123 | #endif |
124 | 124 | ||