[phobos] Fwd: Re: Ruling out arbitrary cost copy construction?
Michel Fortin
michel.fortin at michelf.com
Mon Nov 1 12:30:54 PDT 2010
Le 2010-11-01 à 14:39, Andrei Alexandrescu a écrit :
> On 11/1/10 10:22 AM, Masahiro Nakagawa wrote:
>> On Mon, 01 Nov 2010 13:21:23 +0900, Andrei Alexandrescu
>> <andrei at erdani.com> wrote:
>>
>>> Alright, then how do we solve refcounting of constant objects (see
>>> Michel Fortin's question)? My solution involves casting away const and
>>> keeping immutability information at runtime. Is that acceptable?
>>
>> Your approach seems to be C++'s mutable. I am acceptable.
>>
>> You said "There are several solutions possible" on digitalmars.D.
>> Can you show the example of other solutions?
>
> One other solution is to simply say
>
> @refcounted struct Widget { ... }
>
> and let the compiler take care of everything.
I think that'd be better. If later you make the optimizer aware that the 'retain' and 'release' operations cancel each other, then a lot of them might simply vanish in optimized code. And other tricks might apply too, like coalescing multiple 'retain' or 'release' into one operation where you increment/decrement the counter by more than one.
But I'm biased: having that in the compiler would also be a great service to me who is currently implementing the (reference-counted) Objective-C object model. Even better: combine that with an ARM backend and D becomes better than Objective-C for iPhone/iPad development (where garbage-collected Objective-C doesn't exist (yet) and you must call retain/release/autorelease explicitly everywhere).
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the phobos
mailing list