<div>Lock-free reference counting is hard to be implemented on architectures without double compare-and-swap instruction(one possible solution is binding counter with the pointer). The overhead of reference counting may be significant.</div>
<div> </div>
<div> </div>
<div>Thanks.</div>
<div>Haoxiang Lin<br></div>
<div class="gmail_quote">2010/11/24 Dana Jansens <span dir="ltr"><<a href="mailto:dana@orodu.net">dana@orodu.net</a>></span><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">2010/11/23 林昊翔 <<a href="mailto:linhaoxiang@gmail.com">linhaoxiang@gmail.com</a>>:<br>
<div class="im">> I think the best way is borrowing constructor and destructor concepts from<br>> C++. For each internal data structure foo, maintain a foo_create function as<br>> the constructor(many data structures are already done), and a foo_destroy<br>
> function as the destructor. Then we avoid duplicate and complicate clean<br>> work at each failure exit in foo_create.<br><br></div>In my own experience, using an unref() (and ref()) - ie. reference<br>counting - for all objects, rather than a destroy(), always pays off.<br>
<br>- Dana<br>
<div class="im"><br>> 2010/11/23 Kristian Høgsberg <<a href="mailto:krh@bitplanet.net">krh@bitplanet.net</a>><br>>><br>>> On Wed, Nov 17, 2010 at 10:16 PM, 林昊翔 <<a href="mailto:linhaoxiang@gmail.com">linhaoxiang@gmail.com</a>> wrote:<br>
>> > The scenario is:<br>>> > struct A *foo()<br>>> > {<br>>> > A *a;<br>>> ><br>>> > a = malloc(sizeof(A));<br>>> > if (a == NULL)<br>>> > return NULL;<br>
>> ><br>>> > a->b = malloc(sizeof(B));<br>>> > if (a->b == NULL)<br>>> > return NULL;<br>>> ><br>>> > return a;<br>>> > }<br>>><br>
>> You're right, there's a bunch of those in the code. Could you please<br>>> create your patches by committing the changes and then either attach<br>>> the output of git format-patch -1 (where -1 means "one commit", use<br>
>> whatever number of patches you have) or even better use git send-email<br>>> -1 --to=<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a>.<br>>><br>>> Thanks,<br>
>> Kristian<br>><br>><br></div>> _______________________________________________<br>> wayland-devel mailing list<br>
<div class="im">> <a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br></div>> <a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
><br>><br></blockquote></div><br>