DIP74: Reference Counted Class Objects
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Tue Mar 3 01:58:12 PST 2015
On 3/3/15 12:53 AM, Volodymyr wrote:
> On Thursday, 26 February 2015 at 21:50:56 UTC, Andrei Alexandrescu wrote:
>> http://wiki.dlang.org/DIP74 got to reviewable form. Please destroy and
> With opAddRef/opRelease class does respondible for its dealocation and
> its own payload so breaks SOLID's single responsibility principle.
Correct. That's a tactical matter that can be addressed e.g. with mixin
> for me better design will be to do it closer to C++'s shared_ptr.
> // maybe with @arc
> struct RefCounter(T)
> void opAddRef();
> void opRelease();
> ref T obj;
> ref size_t count;
> RefCounter!Widged myRefToWidget;
> RefCounter with default ctor/dtor. opAddRef and opRelease is for
> compiler optimtimisation and elimination of redunadant ref counter
We couldn't make that work with safety.
More information about the Digitalmars-d