Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!usc!polyslo!ttwang
From: ttwang@polyslo.CalPoly.EDU (Thomas Wang)
Newsgroups: comp.lang.c++
Subject: Re: efficiency affecting class interface
Message-ID: <1989Sep30.045137.18628@polyslo.CalPoly.EDU>
Date: 30 Sep 89 04:51:37 GMT
References: <4491@internal.Apple.COM>
Reply-To: ttwang@polyslo.CalPoly.EDU (Thomas Wang)
Distribution: usa
Organization: Cal Poly State University -- San Luis Obispo
Lines: 39

wrl@apple.com (Wayne Loofbourrow) writes:
>Ok.  But now lets say you've got a more complicated beast with
>lots of pointers chaining off of it.  For example, a graph object
>implemented with various linked lists (say vertex lists).

>graph a,b,c;
>// compute b and c
>a = b + c;

>All sorts of copying is going on, and each time an entire graph is
>created (zillions of allocations and all).

When you have BIG objects it makes sense to have a 'handle' class which
manages copying.  The 'handle' class would be very small, and contains a
real pointer to the 'graph' object.  So when a handle_graph object get
copied, it takes very small CPU time.  Then you make all the functions to
operate with the handle class.

class handle_graph
{
  graph* real_ptr;
  int    ref_count;
public:
  graph* ptr() { return real_ptr; }
  ptrcopy(handle_graph&, handle_graph&);
  fieldcopy(handle_graph&, handle_graph&);
};

This is reference counting.  With a set of class templates, the handle
definition can be generated semi-automatically.  I am in the process of
writing such a beast.

>Wayne Loofbourrow

 -Thomas Wang ("This is a fantastic comedy that Ataru and his wife Lum, an
                invader from space, cause excitement involving their neighbors."
                  - from a badly translated Urusei Yatsura poster)

                                                     ttwang@polyslo.calpoly.edu