How the Nasal GC works: Difference between revisions

Jump to navigation Jump to search
m
Line 431: Line 431:


This also means that we basically just need to provide an alternate naGC_get() function, next to the existing one, to add support for alternate GC schemes.
This also means that we basically just need to provide an alternate naGC_get() function, next to the existing one, to add support for alternate GC schemes.
= Disabling the current GC =
The overhead caused by managing the memory pools and constantly scanning the  heap (mark/reap) can be examined by modifying the naGC_get() function such that it no longer uses any pool memory, but directly allocates malloc()/naAlloc() - without ever freeing any memory (i.e. leaking). While the fgfs process will eventually get killed this way, the GC will be basically switched off.
<syntaxhighlight lang="C">
struct naObj** naGC_get(struct naPool* p, int n, int* nout)
{
    struct naObj** result;
    naCheckBottleneck();
    LOCK();
#define LEAKY
#ifndef LEAKY
    while(globals->allocCount < 0 || (p->nfree == 0 && p->freetop >= p->freesz)) {
        globals->needGC = 1;
        bottleneck();
    }
    if(p->nfree == 0)
        newBlock(p, poolsize(p)/8);
    n = p->nfree < n ? p->nfree : n;
    *nout = n;
    p->nfree -= n;
    globals->allocCount -= n;
    result = (struct naObj**)(p->free + p->nfree);
#else
    result = (struct naObj**) naAlloc( naTypeSize(n) );
#endif
    UNLOCK();
    return result;
}
</syntaxhighlight>


= bottleneck() =
= bottleneck() =

Navigation menu