From: Daniel Frey (d.frey_at_[hidden])
Date: 2008-04-23 07:14:16
On Tue, 2008-04-22 at 19:48 -0400, Frank Mori Hess wrote:
> 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.
I'll need some time to think about that.
In the meantime, I noticed another improvement, see the attached patch.
Looking at the comments just above init_internal_shared_once(), this
seems to open up even more optimization possibilities. Since I think you
wrote it and I don't know the internals as well as you, maybe you could
elaborate on the comment and what could be improved given that the
pointer inside of the deleter is not used anyway...