
On Wed, 2008-04-09 at 20:13 -0400, Frank Mori Hess wrote:
On Wednesday 09 April 2008 17:26 pm, Daniel Frey wrote:
On Wed, 2008-04-09 at 17:06 -0400, Frank Mori Hess wrote:
think of. Of course, you would still be inflicted with a vtable, but that doesn't add any per-object space overhead, which seems to be what you're most concerned about.
A vtable means that the per-object size *does* grow, since each object needs a pointer to the vtable.
Oh, yeah. Well, it could be done generically too without even a vtable, if shared_ptr recognized a template class which the user could define specializations of.
I attached a minimalistic patch against the trunk which enhances the current code into that direction. The name (enable_shared_from_this_base) is probably not a good name. I think that from shared_ptr's point of view, it doesn't need to know what the callback is used for. It might be better to call it notify_on_ownership or something in that direction. And the callback function should probably also be renamed. Suggestions? The next logical step would be to add another ctor for the low_overhead_enable_shared_from_this, i.e. a ctor for shared_ptr which takes a plain pointer and a weak_count or a shared_count?). Or it might be possible to generalize that case with the current special ctor that takes the ignore_enable_shared_from_this_tag, but that's a second patch on top of the first one, which I will try to write when my time permits. Regards, Daniel