Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-pcd!hplsla!jima From: jima@hplsla.HP.COM (Jim Adcock) Newsgroups: comp.lang.c++ Subject: Re: Support for movable objects in C++ Message-ID: <6590272@hplsla.HP.COM> Date: 2 Oct 89 18:01:19 GMT References: <1989Sep30.051559.20644@polyslo.CalPoly.EDU> Organization: HP Lake Stevens, WA Lines: 45 >/ hplsla:comp.lang.c++ / ttwang@polyslo.CalPoly.EDU (Thomas Wang) / 10:15 pm Sep 29, 1989 / >There is a feature or mis-feature in C++ that makes building a copying >garbage collector difficult. Copying garbage collector have two advantages >over non-copying garbage collector: (1) Copying garbage collector compacts >the heap automatically. (2) Frequently used objects can be copied together >for better locality of reference. > >Copying garbage collector moves an object from one space to another space. >Moving and copying are different, because when you move an object to a new >location, the object at the old location is discarded. > >Say that I am in the middle of a member function of object 'obj'. And the >collector has decided to move 'obj' to a new location. The problem is that >the value of 'this' in the member function will still point to the old >location. > >I propose that C++ be improved, so if one writes: > >volatile class foo >{ ... }; > >The definition of au1_this be changed from foo* to foo**. >All the usages of au1_this would be (*au1_this) -> instead of au1_this ->. > >This way, when I update the value of the master pointer to the new location, >the value of 'this' will automatically be correct. > > -Thomas Wang (Ah so desu ka!) > Essentially, this just strikes me as another call for using handles to objects, rather than just objects themselves. If one believes that garbage collection is a central aspect of OOP, and that copying garbage collectors are the way to go, then one uses handles, and gets a language that looks like one of the many sons and daughters of Smalltalk. If one does not believe that GC is central to OOP, and that one is better off to try to avoid GC as much as possible, and that when one does GC one need not do copy collection -- then one does not use handles, and can make good use of the efficiency of C++ -- not requiring multiple indirection to do simple things. I don't believe copying and compacting are necessary in C++ where GC is typically a secondary concern. Look again at Boehm's GC system and/or buddy systems.