#include <stackbufferallocator.h>
A StackBufferAllocator can be used if a large number of allocations shall be done in the sequel, and either all of those allocations will be freed together at a later point, or they will be freed in reverse order (LIFO). If all allocations will be freed together, set the LIFO template parameter to false, then there is practically no memory overhead for each allocation. For a de-allocation in reverse order, set LIFO to true. Then a structure of the size of two Ints has to be added for each allocation for bookkeeping purposes.
BLOCK_SIZE | Minimum size of each memory block which is obtained from ALLOCATOR. |
LIFO | Use true if you want to use this allocator in a stack-like LIFO way. This adds some overhead. If set to false, no actual de-allocation will happen until all allocations have been freed. |
ALLOCATOR | The parent allocator from which this allocator shall obtain its memory. |
Classes | |
struct | Header |
Public Member Functions | |
StackBufferAllocator () | |
StackBufferAllocator (StackBufferAllocator &&other) | |
void * | Alloc (Int size, MAXON_SOURCE_LOCATION_DECLARATION) |
void | Free (const void *ptr) |
~StackBufferAllocator () | |
void | Flush () |
Static Public Member Functions | |
static Bool | IsCompatibleWithDefaultAllocator (void *) |
Private Attributes | |
ALLOCATOR | _allocator |
BaseArray< Char * > | _memory |
Header | _header |
Char * | _end |
Int | _allocCount |
StackBufferAllocator | ( | StackBufferAllocator< BLOCK_SIZE, LIFO, ALLOCATOR > && | other | ) |
~StackBufferAllocator | ( | ) |
void* Alloc | ( | Int | size, |
MAXON_SOURCE_LOCATION_DECLARATION | |||
) |
void Free | ( | const void * | ptr | ) |
void Flush | ( | ) |
Marks all previously made allocations as freed. This is a really quick operation which removes the need to call Free for each allocated pointer individually. However, it doesn't free the memory blocks themselves, they will be re-used for the next allocations.
|
static |
Returns if a memory block allocated via this allocator can be reallocated or freed by the DefaultAllocator.
|
private |
|
private |
|
private |
|
private |