27#define SMALL_CHUNK 0x100
28#define MEDIUM_CHUNK 0x1000
29#define BIG_CHUNK 0x10000
34template <
int ChunkSize>
54 template <
typename T> T*
Alloc();
73template <
int ChunkSize>
76 currentChunk(nullptr),
85template <
int ChunkSize>
95template<
int ChunkSize>
99 this->retiredChunks = rhs.retiredChunks;
100 this->currentChunk = rhs.currentChunk;
101 this->iterator = rhs.iterator;
103 rhs.retiredChunks.Clear();
104 rhs.currentChunk =
nullptr;
105 rhs.iterator =
nullptr;
111template<
int ChunkSize>
124template<
int ChunkSize>
128 this->retiredChunks = rhs.retiredChunks;
129 this->currentChunk = rhs.currentChunk;
130 this->iterator = rhs.iterator;
132 rhs.retiredChunks.Clear();
133 rhs.currentChunk =
nullptr;
134 rhs.iterator =
nullptr;
140template<
int ChunkSize>
152template <
int ChunkSize>
156 if (this->currentChunk !=
nullptr)
157 this->retiredChunks.Append(this->currentChunk);
159 this->iterator = this->currentChunk;
165template<
int ChunkSize>
169 for (i = 0; i < this->retiredChunks.Size(); i++)
173 if (this->currentChunk)
175 this->retiredChunks.Clear();
176 this->currentChunk =
nullptr;
177 this->iterator =
nullptr;
183template <
int ChunkSize>
189 if constexpr (
sizeof(T) > ChunkSize)
193 this->retiredChunks.Append(block);
200 if (this->iterator ==
nullptr)
207 SizeT remainder = ChunkSize -
SizeT(this->iterator - this->currentChunk);
208 if (remainder < alignedSize)
212 ret =
new (this->iterator) T;
213 this->iterator += alignedSize;
221template <
int ChunkSize>
227 if constexpr (
sizeof(T) > ChunkSize)
231 this->retiredChunks.Append(block);
232 ret =
new (block) T[num];
238 if (this->iterator ==
nullptr)
245 SizeT remainder = ChunkSize -
SizeT(this->iterator - this->currentChunk);
246 if (remainder < alignedSize)
250 ret =
new (this->iterator) T[num];
251 this->iterator += alignedSize;
259template <
int ChunkSize>
265 if (size > ChunkSize)
269 this->retiredChunks.Append(block);
276 if (this->iterator ==
nullptr)
282 PtrDiff remainder = this->currentChunk + ChunkSize - this->iterator;
283 if (remainder < size)
286 ret = this->iterator;
287 this->iterator += size;
Allocates memory in chunks.
Definition arenaallocator.h:36
~ArenaAllocator()
destructor
Definition arenaallocator.h:87
void * Alloc(SizeT size)
allocate new chunk of size
Definition arenaallocator.h:261
T * Alloc()
allocate new object, and calls constructor, but beware because this allocator does not run the destru...
Definition arenaallocator.h:186
ArenaAllocator()
constructor
Definition arenaallocator.h:75
ArenaAllocator(ArenaAllocator &&rhs)
move constructor
Definition arenaallocator.h:97
ArenaAllocator(const ArenaAllocator &rhs)
copy constructor
Definition arenaallocator.h:113
void operator=(const ArenaAllocator &rhs)
assignment operator
Definition arenaallocator.h:142
byte * currentChunk
Definition arenaallocator.h:65
void operator=(ArenaAllocator &&rhs)
move operator
Definition arenaallocator.h:126
Util::Array< byte * > retiredChunks
Definition arenaallocator.h:67
T * Alloc(SizeT num)
Allocate several new objects of a specific type.
Definition arenaallocator.h:224
byte * iterator
Definition arenaallocator.h:66
void Release()
release all memory
Definition arenaallocator.h:166
void NewChunk()
retires a chunk and creates a new one (might waste memory)
Definition arenaallocator.h:154
Nebula's dynamic array class.
Definition array.h:60
#define n_assert(exp)
Definition debug.h:50
Nebula compiler specific defines and configuration.
__forceinline unsigned int align(unsigned int alignant, unsigned int alignment)
Definition scalar.h:722
Definition arenaallocator.h:31
void * Alloc(HeapType heapType, size_t size, size_t alignment)
Allocate a block of memory from one of the global heaps.
Definition osxmemory.cc:56
void Free(HeapType heapType, void *ptr)
Free a block of memory.
Definition osxmemory.cc:136
@ ObjectArrayHeap
Definition osxmemoryconfig.h:28
Nebula's scalar datatype.
ptrdiff PtrDiff
Definition types.h:53
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48