Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!rutgers!usc!wuarchive!uunet!bellcore!backyard!aaron From: aaron@backyard.Berkeley.EDU (Aaron Akman) Newsgroups: comp.lang.c++ Subject: Re: garbage collection and member functions Message-ID: <1990Dec20.161737.7027@bellcore.bellcore.com> Date: 20 Dec 90 16:17:37 GMT References: <1990Dec20.045909.7681@rice.edu> Sender: usenet@bellcore.bellcore.com (Poster of News) Reply-To: aaron@backyard.Berkeley.EDU (Aaron Akman) Organization: Bell Communications Research Lines: 51 In article <1990Dec20.045909.7681@rice.edu>, dougm@zamenhof.rice.edu (Doug Moore) writes: |> |> Please give a thought to the following problem if garbage collection |> interests you. Otherwise, skip it. |> To be honest I didn't exactly understand the problem you are running into, but I tried to implement something similar: lisp-style cons-ing w/auto garbage collection. I also overrode new for underlying class(es?), and I had some success. I don't have the code before me, but here's what I remember: I created 2 objects, one roughly the same as your SExpression and one called LispObj. When I declared: LispObj x; The object 'x' automatically linked itself into a list that I wanted to mimic the old Obarray in lisp (I hope I'm getting the jargon right). That's the list of things my garbage collector won't collect (their still in-use). The LispObj points to one of my SExpression objects which it gets by calling the SExpression's overridden new(). The SExpression's are managed in a big pool, and new() gets one from the free list, which starts out as everything. When 'x' goes out of scope, and its destructor is called, it takes itself out of the list of LispObj's that are still in-use. I used a regular mark and sweep GC, and used my Obarray to identify what's still in-use. My CONS function operated on 2 LispObj's, and I had user-defined conversions from string, SExpression, and integer to LispObj. The compiler-supplied LispObj didn't go out of scope until the next close brace, so this: LispObj y; { x = cons("hello", cons("goodbye", y)); } would safely tuck away anything important dangling off of y before the close brace, and any excess would automatically get GC-ed. I realize you are trying to do something much bigger (your own eval()), but the basic idea I used was: have 2 objects, (1) that comes from the pool and isn't used directly, and (2) one that encapsulates the first and links itself into an Obarray. GC uses the list of (2) to figure out which (1) are still in-use. Hope that helps. Aaron, bellcore!cheetah!aaron