![]() |
Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
#include <elm/alloc/StackAllocator.h>
Classes | |
struct | chunk_t |
class | ChunkIter |
Public Types | |
typedef char * | mark_t |
Public Member Functions | |
StackAllocator (t::size size=4096) | |
virtual | ~StackAllocator (void) |
void * | allocate (t::size size) |
template<class T > | |
void * | allocate () |
void | free (void *block) |
void | clear (void) |
mark_t | mark (void) |
void | release (mark_t mark) |
template<class T > | |
T * | allocate (int n=1) |
Static Public Attributes | |
static StackAllocator | DEFAULT |
Protected Types | |
typedef struct elm::StackAllocator::chunk_t | chunk_t |
Protected Member Functions | |
virtual void * | chunkFilled (t::size size) |
t::size | chunkSize (void) const |
void | newChunk (void) |
A stack allocator allows to implement quick allocation scheme with even quicker de-allocation. The allocation is performed as in stack, moving a simple pointer. Conversely, the de-allocation is as quick as resetting this pointer to a previous position.
Note that the allocation is only bound by the system memory: the stack is split in chunks. Each time a chunk is full, a new one is allocated.
|
protected |
This type represents the marks of the stack position.
StackAllocator | ( | t::size | size = 4096 | ) |
Build a new stack allocator.
size | The size in bytes of the chunks (default to 4Kb). |
|
virtual |
References StackAllocator::clear().
|
inline |
References StackAllocator::allocate().
Referenced by StackAllocator::allocate(), and StackAllocator::chunkFilled().
|
inline |
References StackAllocator::allocate().
Allocate a new block.
size | Size of the block. |
BadAlloc | If there is no more memory. |
References StackAllocator::chunkFilled().
Referenced by BlockAllocator< T >::allocate().
This method is called when there is no more place in the current chunk. It may be overload to provide custom behavior of the allocator.
size | Size of block to allocate. |
References StackAllocator::allocate(), and StackAllocator::newChunk().
Referenced by StackAllocator::allocate().
Clear all allocated memory.
References StackAllocator::chunk_t::next.
Referenced by StackAllocator::~StackAllocator().
Free the given block.
block | Block to free. |
StackAllocator::mark_t mark | ( | void | ) |
Return a mark on the current stack position. The returned mark may be used to free the next allocated object after the mark set.
Referenced by StackAllocator::release().
Allocate a new chunk.
References StackAllocator::chunk_t::buffer, and StackAllocator::chunk_t::next.
Referenced by StackAllocator::chunkFilled().
Release the stack onto the given mark.
mark | Stack position to free onto. |
References StackAllocator::chunk_t::buffer, StackAllocator::mark(), and StackAllocator::chunk_t::next.
|
static |
Default stack allocator.