Create a CSpace

The free function CreateCSpace() creates a CSpace.

Each CSpace supports a garbage collector which automatically deletes objects registered in the CSpace that are unreachable from the GC roots. A CSpace has a dedicated thread for performing garbage collections, by default one per second.

A CSpace has a mutex to control access to the objects in the CSpace. CreateCSpace() returns a CSpace which is unlocked.


const int32 CEDA_GC_THREAD_DONT_START = -2;
const int32 CEDA_GC_THREAD_NO_SLEEP = -1;
const int32 CEDA_DEFAULT_MILLISECS_PER_GC = 1000;

$function+ CSpace* CreateCSpace(
    int32 milliSecsPerGC = CEDA_DEFAULT_MILLISECS_PER_GC,
    GCThreadFn fn = GCThreadFn())

Create a CSpace. Initially the CSpace is not locked.

milliSecsPerGC affects the GC thread as follows:

milliSecsPerGC action
CEDA_GC_THREAD_DONT_START Don't start the GC thread. It can be started later by calling SetMilliSecsPerGc() then StartGc()
CEDA_GC_THREAD_NO_SLEEP Start the GC thread and allow it to run as fast as possible without Sleep() calls. This option is only intended for testing purposes (no sleeps increases the chances of finding race conditions)
>= 0 The GC thread sleeps for milliSecsPerGC between each GC


$function+ CSpace* CreateCSpace2(int32 milliSecsPerGC)

todo: only needed because we don't support default arguments in Python yet.