[prev in list] [next in list] [prev in thread] [next in thread] 

List:       boost-users
Subject:    Re: [Boost-users] boost::weak_ptr and boost::intrusive_ptr
From:       "Peter Dimov" <pdimov () mmltd ! net>
Date:       2006-12-01 21:15:37
Message-ID: 020201c7158d$dc391910$6607a8c0 () pdimov2
[Download RAW message or body]

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. :-) 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic