Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-10-18 15:21:54


----- Original Message -----
From: <williamkempf_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, October 18, 2001 2:52 PM
Subject: [boost] Re: shared_ptr bug?

> --- In boost_at_y..., "Fernando Cacciola" <fcacciola_at_g...> wrote:
> >
> > ----- Original Message -----
> > From: David Abrahams <david.abrahams_at_r...>
> > To: <boost_at_y...>
> > Sent: Thursday, October 18, 2001 12:24 PM
> > Subject: Re: [boost] shared_ptr bug?
> >
> >
> > > Can we do better with a single-pointer-chained-count design?
> > >
> > > +-ptr-+ +-count-+ +-target-+
> > > | | | | | | |
> > > | *=======>| 1 | *======>| |
> > > | | | | | | |
> > > +-----+ +---+---+ +--------+
> > >
> > I'm not aware of this design. Could you point me to any online
> reference
> > that I can look at?
>
> If I understand the picture, what's proposed is going from this:
>
> template<typename T> class shared_ptr {
> // removed for clarity
> T* px;
> long* pn;
> };
>
> to this:
>
> template<typename T> class shared_ptr {
> // removed for clarity
> struct count { T* px; long n; }
> count* pc;
> };
>
Aha, I see. Thank you.

> This may well simplify the implementation, but it would add a level
> of indirection when dereferencing the "pointer". I suppose some
> tricky casting could eliminate that, but I'm not sure it would be
> portable ( reinterpret_cast<T*>(pc); ).
>
Unfortunately, the double dereferencing cannot be avoided in anyway, since
however you look at it, there is a pointer to a pointer.
For instance, "reinterpret_cast<T*>(pc)" won't work; it should be
"reinterpret_cast<T*>(*pc)", so there is still a double dereferencing.

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk