Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2006-03-31 13:02:44


On 03/31/2006 04:05 AM, Larry Evans wrote:
[snip]
> IOW, the smart_ptr, say sp<T,O>, where T is the referent type
> and O is the overhead type, would have, *intead* of a CTOR taking
> a raw T*:
>
> sp<T,O>::sp(T* a_T)
> : my_ovhd(new O)
> , my_ref(a_T)
> {...}
>
> or an auto_ptr:
>
> sp<T,O>::sp(std::auto_ptr<T> a_T)
> : my_ovhd(new O)
> , my_ref(a_T.release())
> {...}
>
> a CTOR taking a auto_overhead:
^should be:
it would have a CTOR taking an auto_overhead:
>
> sp<T,O>::sp(auto_overhead<T,0>& a_ovhd)
^should be:
       sp<T,O>::sp(auto_overhead<T,Ovhd>&a a_ovhd)
> : my_ovhd(a_ovhd.overhead())
> , my_ref(a_ovhd.release())
> {...}
where Ovhd is something like:

   template<class Referent>
   struct strong_weak_counts
   {
      unsigned strong_count;
      unsigned weak_count;
   };

or it could just contain a single count or just a mark bit
for mark-sweep collection.

However, I've looked more closely at the code, and I see
referent_overhead_ptrs is being used. It's not apparent
how that saves allocation time, but maybe I need to look
closer. What I had in mind was using a pointer to:

   class overhead_referent_vals
   : public Overhead<Referent>
   , public Referent
   {...};

inside the sp<Referent,?>, i.e.

     overhead_referent_vals<Overhead<Referent>,Referent>*
sp<Referent,Overhead>::
     my_ptr;

  As you can see, overhead_referent_vals
has the overhead at the start; hence, the sp<>.get() would just return
a pointer the 2nd superclass.
part, i.e. the Referent*.

[snip]


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