On 2013-05-23 23:42:10 +0000, Manu <turkey...@gmail.com> said:

I have thought of making a similar RefCounted template, but where the
refCount is stored in a hash table, and the pointer is used to index the
table.
This means the refCount doesn't pollute the class/structure being
ref-counted, or avoids a double-indirection on general access.
It will be slightly slower to inc/decrement, but that's a controlled
operation.
I would use a system like this for probably 80% of resources.

I just want to note that this is exactly how reference counts are handled in Apple's Objective-C implementation, with a spin-lock protecting the table.

Actually, on OS X (but not on iOS) there's 4 tables (if I remember well) and which table to use is determined by bits 4 & 5 of the pointer. It probably helps when you have more cores.

--
Michel Fortin
michel.for...@michelf.ca
http://michelf.ca/

Reply via email to