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

#include <elm/alloc/ListGC.h>

+ Inheritance diagram for ListGC:

Classes

class  block_t
 

Public Member Functions

 ListGC (GCManager &m, int limit=1024)
 
 ~ListGC ()
 
voidallocate (t::size size) override
 
void runGC () override
 
bool mark (void *data, t::size size) override
 
void disable () override
 
void enable () override
 
void clean () override
 
- Public Member Functions inherited from AbstractGC
 AbstractGC (GCManager &m)
 
virtual ~AbstractGC ()
 
virtual void free (void *block)
 
template<class T >
voidalloc ()
 

Additional Inherited Members

- Protected Attributes inherited from AbstractGC
GCManagermanager
 

Detailed Description

A simple garbage collector allocator from the main heap but keep trace of the allocated objects to release them automatically.

The GC is automatically triggered when the difference of the number of allocated object since the last GC cycle is bigger than a configuration limit.

Constructor & Destructor Documentation

◆ ListGC()

ListGC ( GCManager m,
int  limit = 1024 
)

Build a list GC.

Parameters
mCurrent garbage collection manager.
limitLimit triggering garbage collection.

◆ ~ListGC()

~ListGC ( )

References ListGC::clean().

Member Function Documentation

◆ allocate()

void * allocate ( t::size  size)
overridevirtual

Allocate a block of the given size. This function is often used this way:

MyClass *p = new(gc.allocate(sizeof(MyClass)) MyClass();
Parameters
sizeSize of the memory to allocate.
Returns
Allocated object.

Implements AbstractGC.

References ListGC::block_t::alloc(), elm::io::p(), and ListGC::runGC().

◆ clean()

void clean ( )
overridevirtual

Clean the memory allocated in the garbage collector and reset it to its initial state.

Implements AbstractGC.

References GCManager::clean(), AbstractGC::manager, and elm::io::p().

Referenced by ListGC::~ListGC().

◆ disable()

void disable ( )
overridevirtual

Disable the automatic run of the garbage collection.

Implements AbstractGC.

◆ enable()

void enable ( )
overridevirtual

Disable the automatic run of the garbage collection. May trigger immediately a GC cycle.

Implements AbstractGC.

References ListGC::runGC().

◆ mark()

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

Record the given block as alive. This function can only be called during a garbage collection cycle.

Parameters
dataPointer to the alive memory block.
sizeSize of the block.
Returns
True if the block has already been collected, false else.

Implements AbstractGC.

References ListGC::block_t::block().

◆ runGC()

void runGC ( )
overridevirtual

Called to start, by hand, a garbage collection cycle. Depending on the underlying implementation, this function may be automatically called by the garbage collector itself. Notice that during a garbage collection cycle, any call to allocate() or alloc() is forbidden.

Implements AbstractGC.

References GCManager::clean(), GCManager::collect(), AbstractGC::manager, and elm::io::p().

Referenced by ListGC::allocate(), and ListGC::enable().


The documentation for this class was generated from the following files:
elm::io::p
Printable< T, M > p(const T &data, const M &man)
Definition: Output.h:302
elm::AbstractGC::AbstractGC
AbstractGC(GCManager &m)
Definition: AbstractGC.h:40