Boost logo

Boost :

From: williamkempf_at_[hidden]
Date: 2001-10-18 12:52:58


--- 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;
};

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

Bill Kempf


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