Newsgroups: alt.lang.design,comp.lang.c,comp.lang.c++,comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!news.duke.edu!news-feed-1.peachnet.edu!emory!swrinde!pipex!uunet!world!tob
From: tob@world.std.com (Tom O Breton)
Subject: Re: Reference Counting (was Searching Method for Incremental Garbage Collection)
Message-ID: <CzrA02.1nr@world.std.com>
Reply-To: tob@world.std.com
Organization: BREnterprises
References: <hbakerCzqzuE.G3E@netcom.com>
Date: Thu, 24 Nov 1994 05:02:26 GMT
X-Posted-By: My own casual posting program
Lines: 79
Xref: glinda.oz.cs.cmu.edu comp.lang.c:117705 comp.lang.c++:100182 comp.lang.lisp:15792

hbaker@netcom.com (Henry G. Baker) writes:
> I'm not trying to be dense.

Right, of course not. I ftp'ed a paper of yours yesterday, you're
obviously not dense.

> What does 'own' mean?

Like in real life, an exclusive association. If A owns something, B, C,
and D et. al. do not own it.

Or to put it another way, when resources such as memory are "owned",
they are controlled by a single thing, and that thing is the only thing
that acquires them and releases them. Non-owners might use the resources
with permission, but only the owner can release them.

If the owner does not disrupt the balance (IE, acquisitions exactly
match releases), and maintains everything inside in a predictable
acquisition-status (EG, a double-linked list might start and end empty,
add every node it allocates, and remove every node it deletes) then we
know that everything inside is not garbage.

The "predictable acquisition-status" need not be the same for everything
inside, it just has to be predictable. For instance, we might have a
convention that some pointers are valid and some aren't, and (of course)
only the valid pointers are in the acquired state. We just have to be
sure that we can always tell them apart, for instance by setting
pointers to a NULL value when we invalidate them.

> What does 'inside' mean?

Depends on exactly what your data structure is. Let's say it's a double
linked list. If you traverse the entire list, the nodes that you
encounter are inside, everything you don't encounter is outside.

But let me see if I can frame a more general answer: Inside == reachable
through a certain set of operations from a given starting point. EG, for
a dll, the operations might be get_prev and get_next and the starting
point might be the head node. Obviously you want to deal with sets of
operations that allow insideness to be controlled from a single point or
at least easily controlled.


> How is ownership transferred and/or controlled?

Transferred: The key is that a resource is owned by exactly one thing,
so if B wants to own something A owns, either A stops owning it (EG: the
node in question is removed from the dll), or B acquires something
equivalent (EG: B makes or receives another copy, which B then owns.)


Controlled: If I understand your question, it depends on what tools your
language gives you. Some languages of course will let you stomp all over
everything and never tell you. I prefer strong typing for control, where
a deep pointer is a different type than a shallow pointer, and only
legal operations can happen among them. But that's just a preference.

> What happens in the presence of exceptions?

Depends how far you unwind. If you unwind far enough that the owner
disappears, then it obviously can no longer own resources. Since it
should have no resources after it "dies", it must either release them or
give them to something else.

If you unwind out of acquisition/releasing routines, obviously you want
to correctly communicate in what state they left the resource.


> These are the kinds of things that need to be made precise in order to
> convert good ideas into a robust, workable _style_ of programming.

Thanks, that was much easier to answer.

        Tom

-- 
tob@world.std.com
TomBreton@delphi.com: Author of The Burning Tower

