|
| Arena () |
|
| ~Arena () |
|
void * | alloc (size_t size) |
| Returns a pointer to a buffer of size bytes. More...
|
|
void | freeTop (void *ptr) |
| Frees the buffer pointed to by ptr. More...
|
|
void | freeAndAllAfter (void *ptr) |
| Frees the buffer pointed to by ptr and all not yet freed allocations that have happened since that buffer was allocated. More...
|
|
template<class T > |
pair< T *, T * > | allocArrayNoCon (size_t elementCount) |
| As alloc(elementCount * sizeof(T)). More...
|
|
template<class T > |
pair< T *, T * > | allocArray (size_t elementCount) |
| As allocArrayNoCon except that constructors for the elements of the array are called. More...
|
|
template<class T > |
void | freeTopArray (T *array, T *arrayEnd) |
| As freeTop(array) except that the elements of the array in the range (array, arrayEnd] are deconstructed in decreasing order of index. More...
|
|
template<class T > |
void | freeTopArray (pair< T *, T * > p) |
| As freeTopArray(p.first, p.second). More...
|
|
template<class T > |
void | freeArrayAndAllAfter (T *array, T *arrayEnd) |
| As freeAndAllAfter(array) except that the elements of the array in the range (array, arrayEnd] are deconstructed in decreasing order of index. More...
|
|
template<class T > |
void | freeArrayAndAllAfter (pair< T *, T * > p) |
| As freeTopArrayAndAllAfter(p.first, p.second). More...
|
|
bool | isEmpty () const |
| Returns true if there are no live allocations for this Arena. More...
|
|
This is an arena allocator.
Arena allocators are very fast at the cost of imposing limitations on how memory can be deallocated.
Allocation and deallocation must occur in stack order (LIFO). In other words, only the most recently allocated buffer that has not been deallocated yet can be deallocated. It is also possible to deallocate all buffers that were deallocated after a given buffer. In DEBUG mode stack order is enforced by ASSERTs.
Arena satisfies allocation requests out of a larger block of memory. When a block is exhausted another block must be allocated using new. This new block is at least twice the size of the previous block. Old blocks are never re-used though they will be deallocated if they become old. So the current block is replaced if and only if it becomes exhausted.
The scheme of geometric block growth is used because it allows a very fast implementation with excellent locality of reference. This can consume memory beyond that which the user of the Arena needs - all allocators have memory overhead. Optimal performance on both speed and memory consumption can usully be reached by all code using the same Arena object when that is possible given the stack-order limitation on deallocation.
All methods throw bad_alloc if backing memory allocation using new fails.
Definition at line 53 of file Arena.h.