Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-10-18 21:02:04


On second thought, it looks like the smart_ptr<derived> => smart_ptr<base>
conversion is not possible with the design below, either.

===================================================
  David Abrahams, C++ library designer for hire
 resume: http://users.rcn.com/abrahams/resume.html

        C++ Booster (http://www.boost.org)
          email: david.abrahams_at_[hidden]
===================================================

----- Original Message -----
From: "Fernando Cacciola" <fcacciola_at_[hidden]>

> > >
> > > > 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.


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