Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!hplabs!hpda!hpcupt1!thomasw From: thomasw@hpcupt1.cup.hp.com (Thomas Wang) Newsgroups: comp.lang.c++ Subject: Re: garbage collection and member functions Message-ID: <7050038@hpcupt1.cup.hp.com> Date: 20 Dec 90 19:07:10 GMT References: <1990Dec20.045909.7681@rice.edu> Organization: Hewlett Packard, Cupertino Lines: 43 / hpcupt1:comp.lang.c++ / dougm@zamenhof.rice.edu (Doug Moore) / 8:59 pm Dec 19, 1990 / >Please give a thought to the following problem if garbage collection >interests you. Otherwise, skip it. > The implementation as it stands allocates new Conses regularly, and > most of them become garbage; I desire to add a copy-collect garbage > collector, to better control memory usage. In order to avoid > rewriting all my code, I choose to overload operator new for Conses, > so that it copies and collects when a call for a new Cons cannot be > immediately satisfied. > But this blows my member functions all to hell. This is a known problem with C++. Copy collector does not work, because of the passing of 'this' pointer. Only way for copying collector to work for C++ is to change the compiler. Precise collector without supporting multiple inheritance can be implemented without changing the compiler. I did the implementation as a master thesis, so this might not be a good class assignment. Conservative collectors are always available though. You can get Boehm's collector via anonymous FTP. > In case you wondered, this was a school assignment. I was the > assigner, not an assignee, and I'm beginning to wonder if it is an > appropriate assignment in light of the ugliness of any solution I can > find. Most straight forward thing I can think of is to use reference counting. It's only a class assignment, so kludgy solution should be fine. Or even don't delete any memory! As long as the program don't run too long, the program should run fine. >Doug Moore -Thomas Wang (Everything is an object.) wang@hpdmsjlm.cup.hp.com thomasw@hpcupt1.cup.hp.com