Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
#include <elm/alloc/BlockAllocatorWithGC.h>
Classes | |
struct | free_t |
Public Member Functions | |
AbstractBlockAllocatorWithGC (t::size block_size, t::size chunk_size=1<< 20) | |
virtual | ~AbstractBlockAllocatorWithGC (void) |
void * | allocate (void) |
bool | needsCollect () const |
bool | isSync () |
void | setSync () |
void | setAsync () |
void | collectGarbage (void) |
t::size | blockSize (void) const |
t::size | chunkSize (void) const |
int | freeCount (void) const |
int | totalCount (void) const |
int | usedCount (void) const |
void * | allocate (t::size size) |
void | free (void *block) |
Protected Types | |
typedef struct elm::AbstractBlockAllocatorWithGC::free_t | free_t |
Protected Member Functions | |
bool | mark (void *ptr) |
virtual void | collect (void)=0 |
virtual void | beginGC (void) |
virtual void | endGC (void) |
virtual void | destroy (void *p) |
Protected Attributes | |
free_t * | free_list |
int | free_cnt |
Implements the block allocator whose template form is BlockAllocatorWithGC.
|
protected |
AbstractBlockAllocatorWithGC | ( | t::size | block_size, |
t::size | chunk_size = 1 << 20 |
||
) |
Build the allocator.
block_size | Size of the blocks. |
chunk_size | Size of the memory chunks (1Mb as a default). |
References Vector< T, E, A >::add(), elm::max(), and Vector< T, E, A >::top().
|
virtual |
References Vector< T, E, A >::count().
Allocate a block of the given size. This function accepts as size only the size of elements.
size | Size of the element. |
BadAlloc | If the allocation fails. |
References AbstractBlockAllocatorWithGC::allocate().
References Vector< T, E, A >::add(), AbstractBlockAllocatorWithGC::collectGarbage(), AbstractBlockAllocatorWithGC::free_cnt, AbstractBlockAllocatorWithGC::free_list, AbstractBlockAllocatorWithGC::free_t::next, Flags< T >::set(), and Vector< T, E, A >::top().
Referenced by AbstractBlockAllocatorWithGC::allocate(), and BlockAllocatorWithGC< node_t >::allocate().
Possibly overridden by the actual implementation, called before starting the garbage collection. As a default, do nothing.
Referenced by AbstractBlockAllocatorWithGC::collectGarbage().
Get the memory chunk size.
This method must be overridden by the actual implementation of the allocation to perform living block collection, that is, call the mark() method for each living block.
Referenced by AbstractBlockAllocatorWithGC::collectGarbage().
Perform a garbage collection.
References AbstractBlockAllocatorWithGC::beginGC(), Flags< T >::clear(), AbstractBlockAllocatorWithGC::collect(), AbstractBlockAllocatorWithGC::destroy(), AbstractBlockAllocatorWithGC::endGC(), AbstractBlockAllocatorWithGC::free_cnt, AbstractBlockAllocatorWithGC::free_list, AbstractBlockAllocatorWithGC::free_t::next, and AbstractBlockAllocatorWithGC::totalCount().
Referenced by AbstractBlockAllocatorWithGC::allocate().
This function is called each time a block is released to the free list to let user perform some cleanup.
p | Pointer to the block. |
Reimplemented in BlockAllocatorWithGC< T >, and BlockAllocatorWithGC< node_t >.
Referenced by AbstractBlockAllocatorWithGC::collectGarbage().
Possibly overridden by the actual implementation, called after ending the garbage collection. As a default, do nothing.
Referenced by AbstractBlockAllocatorWithGC::collectGarbage().
Function for compatibility with Allocator concept. Do nothing yet.
block | Block to free. |
|
inline |
References AbstractBlockAllocatorWithGC::free_cnt.
Referenced by AbstractBlockAllocatorWithGC::usedCount().
|
inline |
Test if the allocator is synchronous or not.
Mark a block is living.
ptr | Pointer on the block to mark. |
References BitVector::bit(), Vector< T, E, A >::count(), and BitVector::set().
Referenced by BlockAllocatorWithGC< node_t >::mark().
|
inline |
Test if garbage collection is required (in synchronous model).
|
inline |
void AbstractBlockAllocatorWithGC::setSync(); Set the allocator synchronous.
Set the allocator asynchronous.
References Flags< T >::clear().
|
inline |
References Flags< T >::set().
int totalCount | ( | void | ) | const |
Compute the total count of allocated blocks (including used and fried ones).
References Vector< T, E, A >::length(), and Vector< T, E, A >::top().
Referenced by AbstractBlockAllocatorWithGC::collectGarbage(), and AbstractBlockAllocatorWithGC::usedCount().
|
inline |
Get the count of apparently used. This count is only precise just after a garbage collection. Else it may includes non-living blocks that have not been already collected.
References AbstractBlockAllocatorWithGC::freeCount(), and AbstractBlockAllocatorWithGC::totalCount().
|
protected |
|
protected |