Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2004-04-23 05:55:02


Rogier van Dalen wrote:
[snip]
>
> FWIW: I have a smart pointer class similar to the boost one, in which the
> ref_count class can contain the object, thus requiring one allocation only:
>
> template <class T> class ref_count {
> char data [sizeof(T)];
>
> long strong_count;
> long weak_count;
> // ....
>
> public:
> // ....
> };
The file:

    */boost/files/managed_ptr/overhead_referent_vals.zip

contains a simple multiple inheritance equivalent parameterized
on the overhead, i.e.

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

>
> There are two major disadvantages to this construction:
> 1. Quite elaborate code is needed to fake parameter forwarding.
This was done with Paul Mensonides' help using preprocessor magic
as acknowledged in the file:
   managed_ptr_ctor_forwarder.hpp
which is included in the zip file.
> 2. The memory needed for T can be deallocated only when the memory for the
> counter is (i.e. when weak_count becomes zero).
Hmm.. that's as it should be, isn't it? After all, the refcount should
stay around as long as the memory to which it refers. AFAICT, that's
how shared_ptr works.


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