Newsgroups: alt.lang.design,comp.lang.c,comp.lang.c++,comp.lang.lisp,comp.lang.ada
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!uhog.mit.edu!europa.eng.gtefsd.com!howland.reston.ans.net!news.moneng.mei.com!uwm.edu!lll-winken.llnl.gov!noc.near.net!inmet!dsd!bobduff
From: bobduff@dsd.camb.inmet.com (Bob Duff)
Subject: Re: Reference Counting (was Re: Searching Method for Incremental Garbage Collection)
Message-ID: <D07J5v.Gvn@inmet.camb.inmet.com>
Sender: news@inmet.camb.inmet.com
Organization: Intermetrics, Inc.
References: <CzHCvp.9rM@rheged.dircon.co.uk> <3bfprn$okr@scipio.cyberstore.ca> <3bg6ci$18k@gamma.ois.com> <DAG.94Nov30090717@bellman.control.lth.se>
Date: Fri, 2 Dec 1994 23:41:54 GMT
Lines: 45
Xref: glinda.oz.cs.cmu.edu comp.lang.c:119020 comp.lang.c++:101420 comp.lang.lisp:15904 comp.lang.ada:24314

In article <DAG.94Nov30090717@bellman.control.lth.se>,
Dag Bruck <dag@control.lth.se> wrote:
>>>>>> "R" == R William Beckwith <beckwb@ois.com> writes:
>
>R> Maybe my perspective is skewed because I have been RC'ing in Ada
>R> 9X.  I realize that C++ calls a copy constructor if you pass an
>R> object as an argument by value.  But I was under the assumption
>R> that every C++ RC'ing implementation worth its salt would require
>R> that the reference objects are passed by reference (&).

>No, why should it?  The copy constructor has to manipulate the RC,
>that's all.  If you pass arguments by reference, RC is not changed
>(you're passing the object, not its value).

In Ada 9X, all controlled types (the ones you can define reference
counting for) are passed by reference.  This seems more efficient than
passing by copy and incr/decr-ing a reference count every time.

Whether reference counting is a good idea or not (vs. "full" Garbage
Collection) is another question -- Henry Baker's many papers on the
subject are quite interesting.

>I was under the impression that the user cannot define the assignment
>operator in Ada.  If so, how can you implement safe RC except by going
>through a private type?

You cannot directly override ":=" in Ada, but ":=" always does
"adjustment", and for controlled types, you can override Adjust.
So you *can* implement safe reference counting in Ada 9X.

Controlled types are not required to be private, but they are required
to be records (or private completed as record).  So you have to wrap
your access type in a record type (a record extension actually) to make
it controlled.

Note that this is done on a per-type basis.  So some types can be
reference-counted while others are not.

>					-- Dag Bruck

- Bob
-- 
Bob Duff                                bobduff@inmet.com
Oak Tree Software, Inc.
Ada 9X Mapping/Revision Team (Intermetrics, Inc.)
