DIP74: Reference Counted Class Objects
Volodymyr via Digitalmars-d
digitalmars-d at puremagic.com
Tue Mar 3 00:53:46 PST 2015
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 discuss.
>
> Thanks,
>
> Andrei
With opAddRef/opRelease class does respondible for its
dealocation and its own payload so breaks SOLID's single
responsibility principle. As for me better design will be to do
it closer to C++'s shared_ptr.
e.g:
// 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 increment/decrement.
More information about the Digitalmars-d
mailing list