Re: The joy of garbage collection



"robbie.carlton@xxxxxxxxx" <robbie.carlton@xxxxxxxxx> writes:

> Hi. Sorry if this is a bit of topic, but I thought people here would be
> more interested than people in comp.lang.c
> I'm writing a simple lisp interpreter, just for the sheer joy of it,
> and I've fallen down a bit at the memory management stage. I want to
> implement a simple mark and sweep garbage collector, and I understand
> how to do the mark part (having dillegently studied Knuth), but it
> seems that the sweep bit is incompatible with storing unboxed data in
> the heap, which I would like to do. Once the gc has marked all of the
> objects that are active, how does it free up the rest, and in what
> sense are they free.

They're free to be allocated for new objects.

> Does the program have to maintain a list of free
> memory somewhere, and if so, how?

Not the program, the memory management module.

It can be done however you want. You can keep a linked list of free
memory cells, or you can move down marked objects at one side of the
heap, and therefore have a big free block on the other side of the
heap, or you can keep a separate bitmap of free memory cells, or
anything else.



If you want to reuse, or just read an example of a simple mark and
sweep gc, have a look at:

cvs -z3 -d :pserver:anonymous@xxxxxxxxxxxxxxxxxxxxx:/usr/local/cvs/public/chrooted-cvs/cvs co common/common-lisp/heap.lisp

http://www.informatimago.com/develop/lisp/


--
__Pascal Bourguignon__ http://www.informatimago.com/

Nobody can fix the economy. Nobody can be trusted with their finger
on the button. Nobody's perfect. VOTE FOR NOBODY.
.


Quantcast