Chris M. Thomasson
2023-12-09 06:27:05 UTC
Food for thought. We can atomically increment a reference count along
with obtaining a reference to an object in a single fetch-and-add. All
in pure C++11
Say we have some objects:
collectors[CN];
And a reference count, say, 32 bit words:
RC = 0xRRRRRRCC
Where R is reference count space, and C is an index into collectors...
So, to obtain a reference we can simply:
word = fetch_and_add(&RC, 0x100);
Now we have incremented the count and obtained an index into the
collectors in one shot without DWCAS. ;^)
I cannot remember if this trick for single word proxy collectors is
patented!
with obtaining a reference to an object in a single fetch-and-add. All
in pure C++11
Say we have some objects:
collectors[CN];
And a reference count, say, 32 bit words:
RC = 0xRRRRRRCC
Where R is reference count space, and C is an index into collectors...
So, to obtain a reference we can simply:
word = fetch_and_add(&RC, 0x100);
Now we have incremented the count and obtained an index into the
collectors in one shot without DWCAS. ;^)
I cannot remember if this trick for single word proxy collectors is
patented!