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

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 27 12:11:10 PDT 2014


On 9/27/14, 1:11 AM, Foo wrote:
>> 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)

So then when does the counter get ever incremented? -- Andrei


More information about the Digitalmars-d mailing list