RCArray is unsafe

Zach the Mystic via Digitalmars-d digitalmars-d at puremagic.com
Tue Mar 3 20:31:38 PST 2015


On Wednesday, 4 March 2015 at 03:46:36 UTC, Zach the Mystic wrote:
> Just my own past posts. My suggestion is based on the compiler 
> doing all the work. I don't know how it could be tested without 
> hacking the compiler.

I think that part of the fear of my idea is that I want structs 
to get some of the behavior suggested in DIP74 for classes, i.e. 
the compiler inserts calls to opAddRef/opRelease on its own at 
certain times. Since structs only have postblits and destructors, 
there's no canonical way to call them as separate functions. The 
behavior I'm suggesting would only be good if you had a 
refcounted type, which means it's superfluous if not harmful to 
insert it "just because" in other types of structs.

If it turns out that some of the behavior desirable for 
refcounted classes is useful for structs too, it may be necessary 
to hint to the complier that a struct is indeed of the refcounted 
type. For example, "void opAddRef();" and "void opRelease();" 
could be specially recognized, with no definitions even permitted 
(error on attempt), implying "alias opAddRef this(this);", "alias 
opRelease ~this;".


More information about the Digitalmars-d mailing list