Escaping the Tyranny of the GC: std.rcstring, first blood

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 24 14:17:08 PDT 2014


On 9/24/14, 1:15 PM, Manu via Digitalmars-d wrote:
> Something like (whatever syntax you like):
>
> int^ rcInt; // refcounted pointer to an int
> MyStruct^ rcStruct; // refcounted pointer to a struct
> MyStruct s; // normal value-type struct, but if the struct has
> opInc/opDec, the RC handling code in the compiler can implicitly
> generate calls to opInc/opDec on assignment, which will allow the
> struct to manage itself.

You're getting confused here, postblit and destructor take care of that.

> Not sure how to express an RC dynamic array... int[^] rcArray? Anyway,
> syntax is whatever it is, I think this approach is what makes sense to
> me though.

Whatever syntax I like? Awesome! How about:

RefCounted!int rcInt; // refcounted pointer to an int
RefCounted!MyStruct rcStruct; // refcounted pointer to a struct
RefCounted!(int[]) rcArray; // refcounted array

The irony is the first two already work with the semantics you need, but 
apparently I've had difficulty convincing you to try them and report 
back. My work on RCString has also gone ignored by you, although it's 
exactly stuff that you're asking for.


Andrei



More information about the Digitalmars-d mailing list