This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: conservative gc


Klaus Schilling <Klaus.Schilling@home.ivm.de> writes:

> In the last posts, it was said repeatedly that the garbage collection of guile
> is conservative.
> 
> What does this mean? Is this related to conservation laws in physics (mass,
> energy, momentum etc.) Is 'mark and sweep' necessarily conservative?
> 
> What alternatives would there be to conservative garbage collection? R*RS
> doesn't recommend any particular gc strategy at all, so may be other scheme
> implementations act differently, even more Common Lisp engines.

Exact GC uses typechecking information and runtime calls (done by the
application) to tag the data to be preserved to till the next cycle
and ONLY THAT DATA. Conservative gc scans bitpatterns rather than
typed data, and marks data that has to be preserved (and possibly some
more).

Guile's GC is a hybrid between the two, as it conservatively scans the
C stack but requires the application to supply type information for
the rest of the memory. In practice, at least for me, it works
greatly, as you can pretend that there is no GC, even in C code -
except for tiny functions you have to write each time you define a new
smob. Conservative scan of the stack does this:

Instead of writing

void foo (SCM blah)
{
    SCM bar = function_call();
    GC_PROTECT(bar);

    ...

    GC_UNPROTECT(bar);
}

you can simply do:

void foo (SCM blah)
{
    SCM bar = function_call();

    ...
}

Conservative gc will find bar on the stack and mark it - this is FAR
less bug-prone than the former version.

-- 
I refuse to use .sig