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

Foo via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 27 14:32:03 PDT 2014


On Saturday, 27 September 2014 at 19:11:08 UTC, Andrei 
Alexandrescu wrote:
> 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

increment: by postblit call
decrement: by dtor call

But if you ask me, we should either use a valid library solution 
like: http://dpaste.dzfl.pl/b146ac2e599a (it is only a draft of 
10 min work)
Or we should extend UDA's, so that:
@rc(int) x; is rewritten to: Rc!int x;


More information about the Digitalmars-d mailing list