|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-12-01 16:15:37
Nat Goodspeed wrote:
> It seems possible to implement weak_ptr notification by building a
> list of weak_ptr instances referencing a given object. If we don't
> want that list to consume additional heap memory, the list could
> itself be intrusive in the weak_ptr objects. If we want it to be
> efficient, we build a doubly-linked list. (This may call for a
> policy-based implementation so the consumer can decide which overhead
> is least noxious.)
This works. It's also completely independent of intrusive_ptr. You can
implement such a weak pointer (and I know people who have done so) without
ever using an intrusive_ptr or reference counting at all. The object
destructor just goes over the list and zeroes the weak pointers. Threads are
problematic and would probably require a per-object mutex.
Another option is to use
http://boost.org/libs/smart_ptr/sp_techniques.html#weak_without_shared
which also doesn't require intrusive_ptr and works for any object, and
handles threads nicely. But you pay for a shared_ptr control block, so it
probably won't satisfy intrusive_ptr users.
Both options are intrusive, but then, so is intrusive_ptr. :-)
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net