Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!lll-winken!decwrl!shlump.nac.dec.com!ashok.dec.com!nadkarni From: nadkarni@ashok.dec.com Newsgroups: comp.lang.c++ Subject: distinguishing stack/heap, garbage collection Message-ID: <9084@shlump.nac.dec.com> Date: 11 Mar 90 19:54:10 GMT Sender: newsdaemon@shlump.nac.dec.com Organization: Digital Equipment Corporation Lines: 24 I'm just learning C++ so maybe I'm missing something obvious. How do you distinguish between class objects allocated on the stack or static store and those allocated on the heap ? I have an application that would benefit greatly from garbage collection. Plenty of circular links so reference count based GC is out. Stop-and-collect is acceptable so I was planning on a simple mark and sweep scheme. However, I can't figure out a way to locate the `roots' (stack/static store) and distinguish them from the GC-able objects. One way might be to overload the new operator for GC classes so that you keep a list of the addresses of such objects and use this list to check if a object is in the heap or not (kind of like Boehm's GC, which I cannot use for some other reasons). But it seems like this check would be too much overhead even for my (so what if it's slow) application. Unless there is a way of telling in a constructor whether the object is allocated on the stack or not and then remembering that info in a tag. Is this possible ? As a related request, someone mentioned a C++ garbage collector (not Bartlett's and not Boehm's) a little while ago. I think it was part of some package (EC++ perhaps?). Since I do not have ftp access, could some kind soul mail it (just the GC part) to me if it is not too big ? Thanks, /Ashok Nadkarni Digital Equipment Corp. Standard disclaimer applies.