Memory management

SAMSON offers two forms of memory management: custom heap management and garbage collection.

Custom heap management

Developers may use custom heap management to avoid frequently allocating and de-allocating small objects from the heap (which is known to slow down execution), by using the SB_HEAP_OBJECT macro in their class declaration:

#include "SBCHeap.hpp"
class MyClass {
SB_HEAP_OBJECT;
public:
MyClass();
virtual ~MyClass();
};

The class definition must then be accompanied by a custom heap implementation, thanks to the macro SB_HEAP_OBJECT_IMPLEMENTATION:

#include "MyClass.hpp"
SB_HEAP_OBJECT_IMPLEMENTATION(MyClass, 4096);

The provided integer is the number of pre-allocated heap objects (this will automatically adapt if more objects are necessary simultaneously).

The SB_HEAP_OBJECT macro redefines the new and delete operator to use the custom heap instead of the regular one, so that client code does not have to be updated when using the two macros SB_HEAP_OBJECT and SB_HEAP_OBJECT_IMPLEMENTATION.

Garbage collection

SAMSON uses a custom referencing mechanism to track references from objects to other objects. This mechanism is used in particular to support the signals and slots mechanism employed to perform e.g. adaptive simulations.

Thanks to this referencing mechanism, SAMSON is able to achieve some form of garbage collection: when a reference target is not referenced anymore, SAMSON deletes it (in the C++ sense).