ROSE 0.11.145.147
|
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 <Sawyer/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. | |
T * | allocNext () |
Allocate one element. | |
void | revert (T *ptr) |
Free all elements back to the specified element. | |
typedef T Sawyer::StackAllocator< T >::Value |
Type of values being allocated.
Definition at line 23 of file StackAllocator.h.
|
inlineexplicit |
Definition at line 32 of file StackAllocator.h.
|
inline |
Definition at line 35 of file StackAllocator.h.
|
inline |
Free unused large blocks.
Definition at line 44 of file StackAllocator.h.
|
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.