On 4/20/06, Stavros Macrakis <macrakis at gmail.com> wrote:
> > I've done some work on a matrix implementation which
> > is an array for storage plus stride and offset for each dimension
> > and some other info such as a reference counter.
>
> Sounds nice!
>
> I'm curious; why do you need a reference count? That sounds difficult
> to implement correctly, and I'd have thought that garbage collection
> would take care of reclaiming the underlying object when no slices of
> it refer to it any more -- assuming anonymous arrays. Or is that for
> copy-on-write?
Yes, it's for copy on write: when refcount > 0 I have to copy
the storage array before writing to it.
The way the code is now written, the refcount may as well
be just a flag to tell whether I own my storage array.
But a more careful (more strongly optimizing) implementation
would decrement all the refcounts when any reference
goes away, and whoever has refcount = 0 becomes the
effective owner. There is doubtless a very large literature on this.
best,
Robert