Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpda!hpcupt1!thomasw From: thomasw@hpcupt1.HP.COM (Thomas Wang) Newsgroups: comp.object Subject: Re: Re: C++ and garbage collection (long, but interesting :->) Message-ID: <-283749998@hpcupt1.HP.COM> Date: 27 Sep 90 17:43:31 GMT References: Organization: Hewlett Packard, Cupertino Lines: 52 / hpcupt1:comp.object / chased@rbbb.Eng.Sun.COM (David Chase) / 2:45 pm Sep 26, 1990 / >One thing I haven't noticed yet is mention of transformations applied >to pointers by an optimizing compiler. >INTERIOR POINTERS >OPTIMIZATION AND THE COLLECTOR >it seems to >me that there is some burden on the proponents of garbage collection >in C++ to demonstrate (dare I say, "prove"?) that their collector will >work with a gc-ignorant optimizing compiler, or else I must charge to >the collector the time wasted by running unoptimized code. Of course, >this needs to be reproved with each new release of the compiler. If one think a pointer is a 32 bit entity, then you are limited to C++ GC implementations that have some undesirable properties. But in today's world, where memory is relatively cheap, there is no reason why a pointer cannot be encapsulated into an abstract data type that understands operations on garbage collection. With this approach, then you need 3 extra requirements for this scheme to work. (1) Every structure must know how many GC pointer it contains, and where. Some virtual GC member functions need to be written for each structure. Manually doing this is tedious, so it is possible to write a template class generator to make this task semi-automatic. (2) GC pointers inside a structure must be initialized to NULL before its constructor is called. This is required, because GC may be triggered during object construction. The implementation is a little bit tricky; I had to use a macro for object creation. (3) There must be a way to know automatically if a GC pointer is root pointer or not. I assume every GC pointer is root, until they become not root. For GC pointers inside a structure, the constructor for that structure will turn all its GC pointers to non-root. The result is a non-conservative C++ collector that is also portable. -Thomas Wang (Everything is an object.) wang@hpdmsjlm.cup.hp.com thomasw@hpcupt1.cup.hp.com