Boost logo

Boost :

From: Frank Mori Hess (fmhess_at_[hidden])
Date: 2008-04-22 19:48:39


On Tuesday 22 April 2008 17:18, Daniel Frey wrote:
>
> Now that the basic patch is committed, here's the next patch to replace
> the _internal_shared_this with _internal_shared_count to save another
> plain pointer.
>
> OK to commit?

It's okay by me. Although, I believe you could drop _internal_shared_count
entirely and instead use the shared_ptr (or it could be a shared_count) in
the deleter wrapper for the same purpose. And, if shared_from_this is not
called prior to a shared_ptr taking ownership then no deleter wrapper will
even be created.

To be more specific, instead of storing _internal_shared_count in the
enable_shared_from_this class, you store it in its own deleter,
intentionally creating a circular reference that keeps it alive. When a
shared_ptr takes ownership, the real owner is put into the deleter
wrapper, breaking the circular reference. It would also require a slight
modification to the deleter_wrapper class, something like a swap_deleter
method, or you could make set_deleter return the old deleter.

-- 
Frank



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