ROSE
0.11.96.11
|
Stack-like allocator.
This allocator allocates single elements of POD type from a stack-like pool. The allocator is intentionally not thread safe and is intended to be used in multi-threaded applications where each thread is allocating and freeing elements in a stack-like order from its own allocator.
Definition at line 21 of file StackAllocator.h.
#include <StackAllocator.h>
Public Types | |
typedef T | Value |
Type of values being allocated. | |
Public Member Functions | |
StackAllocator (size_t elmtsPerBlock) | |
void | prune () |
Free unused large blocks. | |
T * | reserve (size_t nElmts) |
Reserve space for objects. More... | |
T * | allocNext () |
Allocate one element. More... | |
void | revert (T *ptr) |
Free all elements back to the specified element. More... | |
|
inline |
Reserve space for objects.
Reserves space for nElmts
elements of type T
and returns a pointer to the first one. Although this reserves space for objects, the memory is not yet usable to store an object. The next allocation request will give back the same address as returned here, unless the allocated is reverted to an earlier address in the mean time.
Definition at line 54 of file StackAllocator.h.
|
inline |
Allocate one element.
If this allocation is below the amount previously reserved then it is guaranteed to be adjacent to the previous allocation.
Definition at line 64 of file StackAllocator.h.
|
inline |
Free all elements back to the specified element.
Reverts the state of this allocator so that the specified ptr
would be the return value from allocNext. If this results in whole large blocks becoming unused they are not returned to the system (call prune if that's desired).
Definition at line 73 of file StackAllocator.h.