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

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 26 15:51:46 PDT 2014


On 9/26/14, 2:50 PM, Dmitry Olshansky wrote:
> 24-Sep-2014 18:55, Andrei Alexandrescu пишет:
>> On 9/24/14, 3:31 AM, Dmitry Olshansky wrote:
>>> 23-Sep-2014 19:13, Andrei Alexandrescu пишет:
>>>> On 9/23/14, 12:17 AM, Dmitry Olshansky wrote:
>>>>> In my imagination it would be along the lines of
>>>>> @ARC
>>>>> struct MyCountedStuff{ void opInc(); void opDec(); }
>>>>
>>>> So that would be a pointer type or a value type? Is there copy on write
>>>> somewhere? -- Andrei
>>>
>>> It would be an intrusively counted type with pointer somewhere in the
>>> body. To put it simply MyCountedStuff is a kind of smart pointer.
>>
>> Then that would be confusing seeing as structs are value types. What
>> you're saying is that a struct with opInc() and opDec() has pointer
>> semantics whereas one with not has value semantics. That design isn't
>> going to fly.
>
> Read that as
> struct RefCounted(T){
>
>      void opInc();
>      void opDec();
> }

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


More information about the Digitalmars-d mailing list