garbage collection in C - (nf)

johnl at haddock.UUCP johnl at haddock.UUCP
Wed Jun 6 13:37:18 AEST 1984

haddock!johnl    Jun  5 14:10:00 1984

I made a garbage collected version of malloc() a while ago for a little
Lisp interpreter I was playing with (no, I didn't malloc atoms and cons
cells, but I did malloc strings and on a Z8000, you need to reclaim all
the space you can get.)

The standard version of malloc() keeps a link list of all of the
storage chunks in the arena.  The low order bit of each link word
is the busy flag.  So to garbage collect, you merely run through
the arena, clearing all of the busy bits, and then walk through
your useful data structures, setting the busy bits (and you can use
the same busy bits to avoid infinite recursion with circular lists.)
Shazam -- you're done, and malloc will cheerfully reuse the free space.

John Levine, ima!johnl

More information about the Comp.lang.c mailing list