DIP74: Reference Counted Class Objects

Manu via Digitalmars-d digitalmars-d at puremagic.com
Sat Feb 28 19:30:05 PST 2015


On 1 March 2015 at 13:13, Andrei Alexandrescu via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 2/28/15 7:01 PM, Manu via Digitalmars-d wrote:
>>
>> On 1 March 2015 at 12:51, Andrei Alexandrescu via Digitalmars-d
>> <digitalmars-d at puremagic.com> wrote:
>>>
>>> On 2/28/15 6:49 PM, Manu via Digitalmars-d wrote:
>>>>
>>>>
>>>> On 1 March 2015 at 12:21, Andrei Alexandrescu via Digitalmars-d
>>>> <digitalmars-d at puremagic.com> wrote:
>>>>>
>>>>>
>>>>> On 2/28/15 5:43 PM, Manu via Digitalmars-d wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>> I'd like to see a struct with RC operators have implicit calls
>>>>>> generated (and elided) for exactly the same set of cases as classes,
>>>>>> in terms of construction/destruction/assignment/passing to/from
>>>>>> functions.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> The short answer is that probably won't happen. -- Andrei
>>>>
>>>>
>>>>
>>>> *sigh* ... ever, or in DIP74?
>>>
>>>
>>>
>>> In the foreseeable future.
>>>
>>>> I presented my 80% case to you before. I just want this to work
>>>> efficiently:
>>>>
>>>> extern(C) void inc(void*);
>>>> extern(C) void dec(void*);
>>>>
>>>> struct X
>>>> {
>>>>     void *thing;
>>>>
>>>>     opInc() { inc(thing); }
>>>>     opDec() { dec(thing); }
>>>> }
>>>
>>>
>>>
>>> struct X
>>> {
>>>    void *thing;
>>>
>>>    this(this) { inc(thing); }
>>>    ~this() { dec(thing); }
>>> }
>>
>>
>> You've conveniently ignored the word 'efficient'.
>
>
> Inserting calls to opAddRef and opRelease, and the rules that allow their
> elision, follow quite closely (albeit not 100% identically) the rules for
> inserting calls to copy constructors and destructors.

The most important case to be elided is the function call case.
Passing struct to function results in postblit and destructor for
every call.
If postblit and destructor were sufficient, we would have been
satisfied with RC in D for years.


>> Okay, so if I'm not better off then I've always been, what is the good
>> of DIP74 to me?
>
>
> The title reads "Reference Counted Class Objects".

That title is not immutable.
If DIP74 is a starting point, and you can see extension to the struct
case in the future, then I'll let this go now.


More information about the Digitalmars-d mailing list