DIP74: Reference Counted Class Objects

Manu via Digitalmars-d digitalmars-d at puremagic.com
Sat Feb 28 17:43:00 PST 2015


On 28 February 2015 at 02:02, Andrei Alexandrescu via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 2/27/15 7:52 AM, Manu via Digitalmars-d wrote:
>>
>> Can I call opAddRef/opRelease from within the postblit/destructor
>> manually and expect the compiler to elide calls correctly?
>> That doesn't seem foolproof though, and you also said manual calls are
>> not @safe. Why not specify a call sequence?
>
>
> Ah, I think you mean structs that have a class member? The compiler will
> insert opAddRef and opRelease appropriately:

Well, not specifically. I mean any struct that has any indirect member(/s).
The point of a struct is that the layout is entirely at user
discretion, and I may want to pass some small RC aggregate by value.

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.
It's at my discretion what the contents of my struct is (in most of my
cases, just pointers to opaque types, but not classes).

If that's not practical (for instance, because classes assign by
reference, but struc opAssign may do anything), then we should be able
to call inc/dec ref manually, and have them optimise correctly? But
that sounds like much more trouble to me.

> =========
> * struct, class, and closure types that have RCO members accommodate calls
> to opRelease during their destruction.
> =========
>
>
> Andrei
>


More information about the Digitalmars-d mailing list