Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!sun-barr!olivea!uunet!orca!bambam!bpendlet From: bpendlet@bambam.dsd.es.com (Bob Pendleton) Newsgroups: comp.lang.c++ Subject: Re: Implementing LISP in C++ (type discrimination) Message-ID: <1991Apr17.233653.25149@dsd.es.com> Date: 17 Apr 91 23:36:53 GMT References: <1991Mar8.024331.14235@searchtech.com> <27D7F621.2F5@tct.uucp> <17238@cadillac.CAD.MCC.COM> <1991Mar12.221015.22144@aero.org> <14342@hacgate.UUCP> Sender: usenet@dsd.es.com Reply-To: bpendlet@dsd.es.com Organization: Evans & Sutherland Design Systems Lines: 43 Nntp-Posting-Host: bambam-gw In article <14342@hacgate.UUCP>, roger@eos.eos.scg.hac.com (Roger Sheldon (Loral)) writes: > OK, so this approach allows you to write elegant code. But how > expensive is this garbage collection technique (which I'm calling > "Immediate" garbage collection since objects are clobbered immediately > after the last reference to it is removed) ? It's called reference counting. It's been used since the dawn of time. Reference counting usually uses more total time than traditional garbage collection. The other cost of reference counting is the storage used by the count associated with each object. For cons cells the counts add 2 to 4 bytes to the size of each cell. Usually a cons cell is only 8 bytes to begin with. A cons cell can be as small as 4 bytes if it contains indexes instead of pointers. So a reference count can chew up a lot of memory. In older languages keeping track of the reference count was error prone. But C++ classes let you hide the details and be sure that the reference count is incremented and decrement at the right times. (Some of the folks around here have coffee cups with "How could the reference count be zero?" (Hi Janet) on them. They're left over from a project written in C that used reference counting. It was a famous and much dreaded runtime error message.) The advantage of reference counting is that the program never "goes to lunch" garbage collecting. Reference counting gives the user consistent response times. Which is something that users love. I think that this one benefit more than justifies the use of reference counts. One thing to consider doing; When the reference count goes to zero put the object on a type specific free list. When you need a new object of a given type try to get it from its type specific free list first. This way your not always going through the general purpose heap code. Avoiding the general purpose code can give you a real performance boost. -- Bob Pendleton, speaking only for myself. bpendlet@dsd.es.com or decwrl!esunix!bpendlet or utah-cs!esunix!bpendlet Tools, not rules.