[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:       "Gottlob Frege" <gottlobfrege () gmail ! com>
Date:       2006-12-01 20:25:13
Message-ID: 97ffb310612011225n29c8fc67rc16a2f34664958a1 () mail ! gmail ! com
[Download RAW message or body]

On 12/1/06, Nat Goodspeed <ngoodspeed@solidworks.com> 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.)
>

Interestingly, since you define the intrusive_ptr_add_ref and release, you
can probably implement the list management without changing intrusive_ptr.

Would you prefer to have the list of weak_ptrs kept on the intrusive_ptr (on
the actual 'intruded' object, actually), or have a global map of
intrusive_ptr object to weak_ptr list?

ie

void intrusive_ptr_release(MyPointer *p)
{
   decr_refcount(p);

   if (refcount(p) == 0)
   {
      weak_ptr_list weaklist = ???  // where does the list come from? from
p? global?

      for_each_weak_ptr_notify_object_gone(weaklist);

      delete p;
   }

}


Tony

[Attachment #3 (text/html)]

<br><br><div><span class="gmail_quote">On 12/1/06, <b class="gmail_sendername">Nat \
Goodspeed</b> &lt;<a \
href="mailto:ngoodspeed@solidworks.com">ngoodspeed@solidworks.com</a>&gt; \
wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, \
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> It seems possible to \
implement weak_ptr notification by building a list<br>of weak_ptr instances \
referencing a given object. If we don't want that<br>list to consume additional heap \
memory, the list could itself be<br>intrusive in the weak_ptr objects. If we want it \
to be efficient, we <br>build a doubly-linked list. (This may call for a \
policy-based<br>implementation so the consumer can decide which overhead is \
least<br>noxious.)<br></blockquote></div><br>Interestingly, since you define the \
intrusive_ptr_add_ref and release, you can probably implement the list management \
without changing intrusive_ptr. <br><br>Would you prefer to have the list of \
weak_ptrs kept on the intrusive_ptr (on the actual 'intruded' object, actually), or \
have a global map of intrusive_ptr object to weak_ptr list?<br><br>ie<br><br>void \
intrusive_ptr_release(MyPointer *p) <br>{<br>&nbsp;&nbsp; \
decr_refcount(p);<br><br>&nbsp;&nbsp; if (refcount(p) == 0)<br>&nbsp;&nbsp; \
{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; weak_ptr_list weaklist = ???&nbsp; // where does \
the list come from? from p? global?<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
for_each_weak_ptr_notify_object_gone(weaklist);<br> \
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delete p;<br>&nbsp;&nbsp; \
}<br><br>}<br><br><br>Tony<br><br>



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

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