Glas :Re: [glas] Reference counting? |
From: Karl Meerbergen (Karl.Meerbergen_at_[hidden])
Date: 2007-10-12 10:14:50
I see what you mean. At this moment, the glas implementation does not do
this. It is not that hard to implement this I think. As Neal points out,
it allows passing arguments by value, which indeed simplifies alot. GLAS
currently passes arguments by value, except containers. This exception
would be removed by the mechanism you describe. it would simplify the
glas implementation as well.
Currently, a view has to be destroyed before the container is destroyed.
I am not sure I understand Neal's comment about storing the count in the
data. If you allocate a vector of double, would you keep one position in
the array for the reference count?
There are consequences that should be thought of carefully:
* if v and w are two vectors (or vector views), what does the operation
w = v do ?
* the storage of vectors and matrices becomes slightly more expensive
I like the idea. Something to think of ...
Thanks,
Karl
Bert Rodiers wrote:
> Hello Karl,
>
> In RogueWave they do the following:
> A vector has a view, which on its turn points to the actual data (a
> C++ data structure aggregating the data).
> When you for example apply a slice on your vector you get a new vector
> with a different view on the same data (the sharing of the data
> happens with reference counting, and the view keeps track of the new
> start, length and stride). The data is cleaned up at the moment no
> views exist anymore. For matrices and higher dimension structures they
> also apply this so that when you extract a column from a matrix the
> data is shared between the original matrix and the vector which was
> the result of the slice.
>
> Regards,
> Bert
>
>
> There you have
>
> On 12/10/2007, *Karl Meerbergen* <Karl.Meerbergen_at_[hidden]
> <mailto:Karl.Meerbergen_at_[hidden]>> wrote:
>
> Hi Bert,
>
> This is the idea of a boost::shared_ptr.
> It is clear that this might help in some cases for improving
> reliability
> of code.
>
> If I understand Neal well, the situation could be the following:
> you create a matrix.
> Later, you create an object that is a proxy to a row of this matrix.
> If you have reference counting, the programmer can destroy the matrix
> before the row proxy. Without the reference count, the proxy should be
> destroyed before the matrix.
>
> At this stage, this mechanism is indeed not provided. In practice, it
> would imply adding a boost::shared_ptr in all containers. This is
> possible, but could it not create undesired overhead?
>
> One of the great things of generic programming is that we can provide
> containers and proxies that support reference counting in addition to
> containers and proxies that do not use reference counting :-)
>
> Karl
>
>
>
> Bert Rodiers wrote:
>
> > Hello Karl,
> >
> > An example:
> >
> > You have a class CVec, the data is stored in seperate class CView to
> > which CVec points. CView also has a reference count. At the
> moment you
> > create a CVec a CView is recreated with reference count 1, when
> a new
> > CVec is created from an existing one, the CView is being shared and
> > the reference count is increased (with a function call). When a
> CVec
> > is destroyed, you decrease the reference count (with a function
> call)
> > and when the reference count becomes zero you destroy the object.
> > I could point you to books that discuss reference counting in more
> > detail...
> >
> > Regards,
> > Bert
> >
> >
> > On 12/10/2007, *Karl Meerbergen* <
> Karl.Meerbergen_at_[hidden] <mailto:Karl.Meerbergen_at_[hidden]>
> > <mailto: Karl.Meerbergen_at_[hidden]
> <mailto:Karl.Meerbergen_at_[hidden]>>> wrote:
> >
> > Hi Neal,
> >
> > I have not thought of this. I am a bit puzzled. Can you explain
> > what you
> > mean by reference counting? Do you mean that a container
> will only
> > disappear when all its references by other objects disappear?
> >
> > Thanks,
> >
> > Karl
> >
> >
> >
> > Neal Becker wrote:
> >
> > >I'm looking at the glas alpha docs. I've been studying blitz++
> > recently, and
> > >I have (so far) liked the use of reference counting.
> > >
> > >A slice of an array returns a (shared) view of the array
> > data. Reference
> > >counting is used for memory management.
> > >
> > >I read the comments in glas regarding assignment vs. copy
> > construction. Have
> > >you considered using ref counting instead?
> > >_______________________________________________
> > >glas mailing list
> > > glas_at_[hidden] <mailto:glas_at_[hidden]>
> <mailto:glas_at_[hidden] <mailto:glas_at_[hidden]>>
> > > http://lists.boost.org/mailman/listinfo.cgi/glas
> <http://lists.boost.org/mailman/listinfo.cgi/glas>
> > >
> > >
> >
> >
> > _______________________________________________
> > glas mailing list
> > glas_at_[hidden] <mailto:glas_at_[hidden]> <mailto:
> glas_at_[hidden] <mailto:glas_at_[hidden]>>
> > http://lists.boost.org/mailman/listinfo.cgi/glas
> >
> >
> >------------------------------------------------------------------------
>
> >
> >_______________________________________________
> >glas mailing list
> >glas_at_[hidden] <mailto:glas_at_[hidden]>
> > http://lists.boost.org/mailman/listinfo.cgi/glas
> >
>
>
> _______________________________________________
> glas mailing list
> glas_at_[hidden] <mailto:glas_at_[hidden]>
> http://lists.boost.org/mailman/listinfo.cgi/glas
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>glas mailing list
>glas_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/glas
>