Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
GroupedGC Class Reference

#include <elm/alloc/GroupedGC.h>

+ Inheritance diagram for GroupedGC:

Public Member Functions

 GroupedGC (t::size size=4096)
 
virtual ~GroupedGC (void)
 
void clear (void)
 
void doGC (void)
 
virtual voidallocate (t::size size)
 
virtual bool mark (void *data, t::size size)
 
void setDisableGC (bool b)
 
- Public Member Functions inherited from DefaultAllocator
voidallocate (t::size size)
 
void free (void *block)
 
virtual ~DefaultAllocator ()
 

Protected Member Functions

virtual void beginGC (void)
 
virtual void collect (void)
 
virtual void endGC (void)
 
bool getNeedGC (void)
 

Additional Inherited Members

- Static Public Attributes inherited from DefaultAllocator
static DefaultAllocator DEFAULT
 

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

◆ GroupedGC()

GroupedGC ( t::size  size = 4096)

Initialize the allocator.

Parameters
sizeSize of chunks.

◆ ~GroupedGC()

~GroupedGC ( void  )
virtual

Member Function Documentation

◆ allocate()

void * allocate ( t::size  s)
virtual

Perform an allocation of the given size.

Parameters
sizeSize of allocated memory.

References elm::cout, GroupedGC::doGC(), and elm::io::endl.

◆ beginGC()

void beginGC ( void  )
protectedvirtual

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

Referenced by GroupedGC::doGC().

◆ clear()

void clear ( void  )

Reset the allocator.

◆ collect()

void collect ( void  )
inlineprotectedvirtual

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 GroupedGC::doGC().

◆ doGC()

◆ endGC()

void endGC ( void  )
protectedvirtual
  1. Adding the non-marked blocks to the free_list
  2. clear c->bits to prevent memory leakage

References elm::cerr, and elm::io::endl.

Referenced by GroupedGC::doGC().

◆ getNeedGC()

bool getNeedGC ( void  )
inlineprotected

◆ mark()

bool mark ( void data,
t::size  size 
)
virtual

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!

Reimplemented from DefaultAllocator.

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

◆ setDisableGC()

void setDisableGC ( bool  b)
inline

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