it doesn't scale on multicore architectures |
Don't care. My problem doesn't work with parallelism. That is, it's not parallelizable.
I'm willing to sacrifice that in exchange for determinism.
Every pointer assignment is an interlocked increment/decrement |
Not exactly. In reality you can optimize away many refcount updates if you can prove the references to the left of the assignment have a shorter lifetime than an assumed original reference.
For example,
1 2 3
|
foreach (var obj in container){
obj.foo();
}
|
There's no need to update obj.refcount twice every loop. The references in container won't just suddenly stop existing halfway through the loop (again, single thread. And either way it's the programmer's fault if they're modifying a structure as it's iterated).
On the other hand,
1 2 3 4
|
foreach (var obj in container){
if (obj.foo())
return () => obj.bar();
}
|
obj's refcount will need an update when obj is passed to the closure constructor, as will the closure's refcount.
Another problem, as noted above, reference counting does not reclaim cycles and for reclaiming cycles, you have to do some kind of a full-GC. |
Yes, it does, and no, you don't.
http://c2.com/cgi/wiki?ReferenceCountingCanHandleCycles
My algorithm is a user-assisted version of this. Python does something similar, but since it's not user-assisted, a full GC is needed and collection of cyclic structures is no longer deterministic.