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

Foo via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 27 01:11:51 PDT 2014


> Consider:
>
> struct MyRefCounted
>     void opInc();
>     void opDec();
>     int x;
> }
>
> MyRefCounted a;
> a.x = 42;
> MyRefCounted b = a;
> b.x = 43;
>
> What is a.x after this?
>
>
> Andrei

a.x == 42
a.ref_count == 1 (1 for init, +1 for copy, -1 for destruction)
b.x == 43
b.ref_count == 1 (only init)


More information about the Digitalmars-d mailing list