@@ -44,23 +44,27 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4444#include " ../Math/Bit.h"
4545
4646#include " Memory.h"
47+ #include " Allocator.h"
48+ #include " ../Thread/TLMAllocator.h"
4749
4850template <typename T>
4951class RingBuffer :
5052 public Tag {
5153
5254 public:
53- RingBuffer () {
55+ RingBuffer ( Allocator* newAllocator = &TLMAlloc ) :
56+ allocator ( newAllocator ) {
5457 }
5558
56- RingBuffer ( const std::string name ) :
57- Tag ( name ) {
59+ RingBuffer ( const std::string name, Allocator* newAllocator = &TLMAlloc ) :
60+ Tag ( name ),
61+ allocator ( newAllocator ) {
5862 }
5963
6064 void Alloc ( const uint64 newElementCount ) {
6165 elementCount = newElementCount;
6266 size = ( elementCount * sizeof ( T ) + 63 ) & ~63 ;
63- memory = ( T* ) Alloc64 ( size );
67+ memory = ( T* ) allocator-> Alloc ( size );
6468
6569 pointer = 0 ;
6670 }
@@ -72,7 +76,7 @@ class RingBuffer :
7276 }
7377
7478 const uint64 tempSize = ( newElementCount * sizeof ( T ) + 63 ) & ~64 ;
75- T* tempMemory = ( T* ) Alloc64 ( tempSize );
79+ T* tempMemory = ( T* ) allocator-> Alloc ( tempSize );
7680
7781 memcpy ( tempMemory, memory, size );
7882
@@ -106,6 +110,7 @@ class RingBuffer :
106110
107111 private:
108112 T* memory;
113+ Allocator* allocator;
109114 uint64 size;
110115 uint64 elementCount;
111116 uint64 pointer;
@@ -117,22 +122,25 @@ class AtomicRingBuffer :
117122
118123 public:
119124 T* memory;
125+ Allocator* allocator;
120126
121127 Timer getTimer;
122128 Timer addTimer;
123129
124- AtomicRingBuffer () {
130+ AtomicRingBuffer ( Allocator* newAllocator = &TLMAlloc ) :
131+ allocator ( newAllocator ) {
125132 }
126133
127- AtomicRingBuffer ( const std::string name ) :
128- Tag ( name ) {
134+ AtomicRingBuffer ( const std::string name, Allocator* newAllocator = &TLMAlloc ) :
135+ Tag ( name ),
136+ allocator ( newAllocator ) {
129137 }
130138
131139 void Alloc ( const uint64 newElementCount ) {
132140 elementCount = newElementCount;
133141 size = ( elementCount * sizeof ( T ) + 63 ) & ~64 ;
134142 mask = elementCount - 1 ;
135- memory = ( T* ) Alloc64 ( size );
143+ memory = ( T* ) allocator-> Alloc ( size, 64 );
136144
137145 memset ( memory, 0 , size );
138146
@@ -151,7 +159,7 @@ class AtomicRingBuffer :
151159 }
152160
153161 const uint64 tempSize = ( newElementCount * sizeof ( T ) + 63 ) & ~64 ;
154- T* tempMemory = ( T* ) Alloc64 ( tempSize );
162+ T* tempMemory = ( T* ) allocator-> Alloc ( tempSize, 64 );
155163
156164 memcpy ( tempMemory, memory, size );
157165
@@ -165,7 +173,7 @@ class AtomicRingBuffer :
165173 }
166174
167175 void Free () {
168- FreeAligned ( memory );
176+ allocator-> Free ( memory );
169177 }
170178
171179 T* GetNextElementMemory ( const uint64 count = 1 ) {
0 commit comments