Archives
 
 
 
  Special
 
 
 
  About Us
 
 
 

Newsletter
Free E-mail Newsletter from BYTE.com

 
    
           
Visit the home page Browse the four-year online archive Download platform-neutral CPU/FPU benchmarks Find information for advertisers, authors, vendors, subscribers Request free information on products written about or advertised in BYTE Submit a press release, or scan recent announcements Talk with BYTE's staff and readers about products and technologies

ArticlesCleaning Up the Garbage


April 1996 / Letters / Cleaning Up the Garbage

In "Clean Up: C++ Garbage Collection" (January), you fail to mention that your garbage-collection scheme, RGC, increases the size of each object using it. You also overlook the fact that the use of the reference-counted classes is far from foolproof. Compilers implement virtual inheritance by embedding hidden pointers--in addition to a class's virtual pointer (vptr)--inside objects inheriting from virtual base classes. There is one such hidden pointer per path to TRGCObj ; given a simple class with no base classes and no virtual functions, adding virtual inheritance from TRGCObj adds two hidden pointers to the class. Complex classes might indirectly inherit from TRGCObj through more than one base class, and each path will contribute another hidden pointer. Your code also depends on the fa ct that reference-counted objects are always allocated on the heap, but this requirement is neither enforced by your classes nor documented in the article. For example,



#include "rgc.h"

class myclass:

public virtual TRGCObj {};

typedef TRGCRef Pmyclass;

void main()

{ myclass m;

Pmyclass A = &m;

}

// m will be deleted here, but

// m is not on the heap!

yields undefined (and typically disastrous) behavior. This doesn't mean that reference counting is a bad technique or that your approach isn't useful. But programmers need to understand the drawbacks before adopting the technique.

Scott Meyers
Author, More Effective C++ (Addison-Wesley, 1996)
smeyers@netcom.com

The RGC garbage-collection scheme does increase the size of each object. This is unavoidable with reference counting, as you must have an extra integer to store the count. Virtual inheritance worsens the problem. You can eliminate virtual inheritance if your class tree is structured such that each class inherits from TRGCObj only once, and thereby save some memory. Regardless, if your program uses a great many objects, it's important to consider that each object is at least one word larger when using any reference-counting garbage collector. As you also point out, RGC does require that objects be allocated from the heap; that is, with new, and not-as-local, variables. Thanks for mentioning these two important points.--Justin Miller, jcmiller@MIT.EDU


Up to the Letters section contentsGo to previous article: Go to next article: DNA by the Numbers...to the LetterSearchSend a comment on this articleSubscribe to BYTE or BYTE on CD-ROM  
Flexible C++
Matthew Wilson
My approach to software engineering is far more pragmatic than it is theoretical--and no language better exemplifies this than C++.

more...

BYTE Digest

BYTE Digest editors every month analyze and evaluate the best articles from Information Week, EE Times, Dr. Dobb's Journal, Network Computing, Sys Admin, and dozens of other CMP publications—bringing you critical news and information about wireless communication, computer security, software development, embedded systems, and more!

Find out more

BYTE.com Store

BYTE CD-ROM
NOW, on one CD-ROM, you can instantly access more than 8 years of BYTE.
 
The Best of BYTE Volume 1: Programming Languages
The Best of BYTE
Volume 1: Programming Languages
In this issue of Best of BYTE, we bring together some of the leading programming language designers and implementors...

Copyright © 2005 CMP Media LLC, Privacy Policy, Your California Privacy rights, Terms of Service
Site comments: webmaster@byte.com
SDMG Web Sites: BYTE.com, C/C++ Users Journal, Dr. Dobb's Journal, MSDN Magazine, New Architect, SD Expo, SD Magazine, Sys Admin, The Perl Journal, UnixReview.com, Windows Developer Network