DIP74: Reference Counted Class Objects

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Fri Feb 27 07:43:20 PST 2015


On 2/27/15 7:17 AM, Manu via Digitalmars-d wrote:
> There's no mention of const/immutable...? Surely we can have RC
> immutable things right? I can't see how that works here... but it's
> very important.

Yah. I've added a TODO.

> I'm not clear on structs. What is the order for calls; postblit,
> opInc, opDec, destructor? 75% of my use cases today are thin structs
> that wrap C/C++ api's.

Structs don't get any special treatment with DIP74, only classes and 
interfaces.

> There's no mention of 'scope'. I presume functions that receive scope
> RC arguments will have the opportunity to have opAddRef/opRelesae
> elided around the call?

That might be a future improvement. In fact that may be possible today; 
I've spoken to an ARC expert who read DIP74 and said Apple's ARC does 
not insert a retain() for a function call, i.e. it assumes functions 
only borrow unless they actually do keep a pointer (e.g. assign to a 
member or global), and only in that case inserts a retain().

If I'm not missing something, we can do this with DIP74 which will 
reduce the opAddRef/opRelease traffic quite a bit.

> I wonder if some standard GetRefCount function should exist? Otherwise
> they will probably end up being named all sorts of different things. I
> guess I can't think of any value in a standardisation of the function
> otherwise though...

Yah, leave that to users.


Andrei




More information about the Digitalmars-d mailing list