Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
elm::SimpleGC Class Referenceabstract

#include <elm/alloc/SimpleGC.h>

Public Member Functions

 SimpleGC (t::size size=4096)
 
virtual ~SimpleGC (void)
 
void clear (void)
 
void doGC (void)
 
void * allocate (t::size size) throw (BadAlloc)
 
void free (void *block)
 

Protected Member Functions

bool mark (void *data, t::size size)
 
virtual void beginGC (void)
 
virtual void collect (void)=0
 
virtual void endGC (void)
 

Detailed Description

Basically, this allocator is a stack allocator that support monitored reference collection for garbage collection. This means that the user is responsible to provide the live references at garbage collection time. This is done by overloading the collect() method and calling mark() on each live block.

Constructor & Destructor Documentation

elm::SimpleGC::SimpleGC ( t::size  size = 4096)

Initialize the allocator.

Parameters
sizeSize of chunks.
elm::SimpleGC::~SimpleGC ( void  )
virtual

Member Function Documentation

void * elm::SimpleGC::allocate ( t::size  size)
throw (BadAlloc
)

Perform an allocation of the given size.

Parameters
sizeSize of allocated memory.
void elm::SimpleGC::beginGC ( void  )
protectedvirtual

Called before a GC starts. Overriding methods must call this one.

References elm::stree::SegmentBuilder< K, T, C >::add(), and elm::stree::SegmentBuilder< K, T, C >::make().

Referenced by doGC().

void elm::SimpleGC::clear ( void  )

Reset the allocator.

void elm::SimpleGC::collect ( void  )
protectedpure virtual

This function is called when references for a garbage collection are needed. It must call the mark() with each alive reference.

This function must be override in each use site in order to provide alive references.

Referenced by doGC().

void elm::SimpleGC::doGC ( void  )

References beginGC(), collect(), and endGC().

void elm::SimpleGC::endGC ( void  )
protectedvirtual

Referenced by doGC().

void elm::SimpleGC::free ( void *  block)
bool elm::SimpleGC::mark ( void *  data,
t::size  size 
)
protected

Called to mark a block as alive.

Parameters
dataAlive data block base.
sizeSize of block.
Returns
True if the block has already been marked, false else.
Warning
This function must only be called from the collect() context!

References elm::_, elm::stree::Tree< K, T, C >::get(), and elm::io::hex().


The documentation for this class was generated from the following files: