Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.lisp Subject: Re: Memory Management in Lisp? Message-ID: <4993@goanna.cs.rmit.oz.au> Date: 18 Mar 91 11:27:14 GMT References: <1991Mar11.173156.24976@aero.org> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 48 In article <1991Mar11.173156.24976@aero.org>, srt@aero.org (Scott "TCB" Turner) writes: > (Richard A. O'Keefe) writes: > >I note that T has "pools", and that if you have "weak references" it is > >easy to implement them in user code, and if you haven't, it's not _that_ > >hard to tell a garbage collector how to flush them. > > The circular discussion is an infamous Usenet phenomenon. (The "Memory > Management" discussion started when I mentioned T's weak reference and > asked if anything similar would ever be in CL.) > > Perhaps you could post some code showing how to implement weak reference > or pools in Common Lisp? Common Lisp, by design, does not include all the low level operations one would need. Given any Common Lisp *implementation*, I doubt that it would be hard to do. Have I any evidence for this claim? It took me all of one hour to add weak references to Elk, and a further half hour to implement pools on top of weak references. This was the very first time I had ever added a data type to Elk. Alas, my operations are not quite the same as the ones in T. If anyone is really interested, I am willing to post my two new files elk/lib/weak.c (143 lines, about 40 are comments) elk/scm/pool (47 lines, about half of that is comments) [no changes are required to any existing file] Now, Elk is unusually easy to augment. (Was that "extension language kit" or "extensible language kit" (:-)?) But T doesn't need a lot of code to implement weak references either. The secret in Elk is a function that looks like void Visit_Weak_Ref(hp, f) Object *hp; int (*f)(); { struct S_Weak *p = WEAK(*hp); p->curval = p->defalt; (*f)(&(p->defalt)); } When the Elk garbage collector is traversing the non-garbage, user- defined types are traversed by a user-defined function. When you create a new type, you specify the function. This is the only part of my implementation of weak references which differs significantly from pairs. (The printing function is different too, of course.) -- Seen from an MVS perspective, UNIX and MS-DOS are hard to tell apart.