Newsgroups: alt.lang.design,comp.lang.c,comp.lang.c++,comp.lang.lisp,zer.z-netz.sprachen.algorithmen
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!Germany.EU.net!EU.net!uunet!allegra!alice!ark
From: ark@research.att.com (Andrew Koenig)
Subject: Re: Reference Counting (was Re: Searching Method for Incremental Garbage Collection)
Message-ID: <CzxoH6.DH8@research.att.com>
Organization: Software Engineering Research Department
References: <CzoCo6.FEB@cunews.carleton.ca> <1994Nov25.234423.17020@njitgw.njit.edu> <1994Nov26.145537.28235@mole-end.matawan.nj.us>
Date: Sun, 27 Nov 1994 16:00:42 GMT
Lines: 51
Xref: glinda.oz.cs.cmu.edu comp.lang.c:118040 comp.lang.c++:100513 comp.lang.lisp:15829

I must confess I haven't followed this posting in detail,
but since I've seen a few messages trying to figure out
what I said earlier, here is a summary of what led up
to it.

Someone mentioned that use counting was a memory allocation
technique that was suitable for many purposes.

Someone else noted that use counting wasn't effective
if circular data structures were involved.

That brought out a comment that circular data structures
were not all that common in practice.

The reply to that was that every doubly linked list has
a circular data structure, as does every tree that uses
a back pointer from each node to its parent.

I noted that such stylized uses of circular data structures
did not cause any particular trouble with use counting,
because understanding the data structure lets you know
which pointers are `backwards' -- those pointers can simply
be ignored in the use-counting algorithm.  Moreover, C++
makes it easy to conceal such pointers from users completely.

Larry Mayka said that my observation might be true for
specific data structures, but that use counting wasn't
effective in general if circular data structures were involved.


All this is certainly true, though it does leave open
the question of how useful circular data structures actually
are in practice.  For example, if we want to store a general
graph, we could view that as a genuinely circular data
structure.  Alternatively, we could view it as a tree
in which the root represents the external view of the
graph, and the leaves represent the vertices.  That has
the pragmatic advantage that it is possible to traverse
the whole graph and, say, print its vertices -- even the
isolated ones.  It also make it possible for use-counted
memory allocation to work again, although admittedly
at the cost of keeping all the vertices around until the
entire graph is no longer needed.

Here is perhaps a more intuitive way to put it:  use
counting is sufficient to implement all the data structure
in Awk.  While that is far from universal, it is certainly
very useful.
-- 
				--Andrew Koenig
				  ark@research.att.com
