RCArray is unsafe

Zach the Mystic via Digitalmars-d digitalmars-d at puremagic.com
Wed Mar 4 10:05:51 PST 2015


On Wednesday, 4 March 2015 at 17:22:15 UTC, Steven Schveighoffer 
wrote:
> Again, I think this is an issue with the expectation of 
> RCArray. You cannot *save* a ref to an array element, only a 
> ref to the array itself, because you lose control over the 
> reference count.

What you need is a special RCSlave type, which is reference 
counted not to the type of its *own* data, but to its parent's. 
In this case, a RCArraySlave!(T) holds data of type T, but a 
pointer to an RCArray, which it decrements when it gets 
destroyed. This could get expensive, with an extra pointer per 
instance than a regular T, but it would probably be safe.


More information about the Digitalmars-d mailing list