<br><br><div class="gmail_quote">On Wed, Nov 3, 2010 at 6:28 PM, Michel Fortin <span dir="ltr"><<a href="mailto:michel.fortin@michelf.com">michel.fortin@michelf.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Le 2010-11-03 à 11:00, Max Samukha a écrit :<br>
<div class="im"><br>
> These notes on copy-constructible Qt types may be useful for the<br>
> discussion:<br>
><br>
> 1. 1/5 (approx. 100 classes) of all classes in core, gui, network, webkit,<br>
> svg and opengl packages define public copy-constructors.<br>
><br>
> A half of those are in reference-counted COW types (approx. 50 classes). The<br>
> remaining 50 classes are reference-counted types without COW, types with<br>
> allocating copy-constructors and types with trivial non-allocating<br>
> constructors.<br>
><br>
> Most of the types with allocating copy-constructors I would probably<br>
> implemented as classes in D. Polymorphic types like QListWidgetItem that<br>
> provide the copy-constructor only for clone() reimplementation should<br>
> definitely be classes in D.<br>
<br>
</div>This prompted me at looking into how reference counting works in Cocoa. Note that all Cocoa objects use reference semantics and are reference counted.<br>
<br>
The reference counter is not stored as part of the object. Instead, reference counters are scattered among 8 global hash tables based on bits 8,9,10 of the pointer value. Each table has its own spinlock which is used for synchronization. On embeded system (iOS presumably), there is only one hash table instead of 8. I guess having many tables is worthless if you have only one core.<br>
<br>
I haven't done any benchmarking, but it seems the assumption is that each thread will use a different memory region that will hopefully fall in a different hash table and thus under a different spinlock and cacheline, which should reduce contention.<br>
<br>
Relevant source code (under the Apple Public Source License):<br>
<br>
See function __CFDoExternRefOperation in<br>
<<a href="http://www.opensource.apple.com/source/CF/CF-550/CFRuntime.c" target="_blank">http://www.opensource.apple.com/source/CF/CF-550/CFRuntime.c</a>><br>
<br>
Spinlock implementation it uses:<br>
<<a href="http://google.com/codesearch/p?hl=fr#pFm0LxzAWvs/darwinsource/tarballs/apsl/Libc-391.tar.gz%7Cz8mNFiEo9vA/Libc-391/i386/sys/OSAtomic.s&q=OSSpinLock%20package:darwin" target="_blank">http://google.com/codesearch/p?hl=fr#pFm0LxzAWvs/darwinsource/tarballs/apsl/Libc-391.tar.gz%7Cz8mNFiEo9vA/Libc-391/i386/sys/OSAtomic.s&q=OSSpinLock%20package:darwin</a>><br>
<div class="im"><br></div></blockquote><div><br>An interesting approach. I wonder how well it performs compared to traditional reference counters.<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">
<br>
--<br>
Michel Fortin<br>
<a href="mailto:michel.fortin@michelf.com">michel.fortin@michelf.com</a><br>
<a href="http://michelf.com/" target="_blank">http://michelf.com/</a><br>
<br>
<br>
<br>
_______________________________________________<br>
</div><div><div></div><div class="h5">phobos mailing list<br>
<a href="mailto:phobos@puremagic.com">phobos@puremagic.com</a><br>
<a href="http://lists.puremagic.com/mailman/listinfo/phobos" target="_blank">http://lists.puremagic.com/mailman/listinfo/phobos</a><br>
</div></div></blockquote></div><br>