Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!hou3c!hocda!houxm!houxz!vax135!floyd!whuxle!mit-eddie!genrad!decvax!cca!ima!haddock!johnl From: johnl@haddock.UUCP Newsgroups: net.lang.c Subject: Re: garbage collection in C - (nf) Message-ID: <180@haddock.UUCP> Date: Tue, 5-Jun-84 23:37:18 EDT Article-I.D.: haddock.180 Posted: Tue Jun 5 23:37:18 1984 Date-Received: Thu, 7-Jun-84 08:23:47 EDT Lines: 17 #R:umcp-cs:-733100:haddock:12400008:000:734 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