Safe reference counting cannot be implemented as a library

Manu via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 28 04:36:53 PDT 2015


On 28 October 2015 at 21:29, David Nadlinger via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On Wednesday, 28 October 2015 at 11:21:17 UTC, Manu wrote:
>>
>> RC is okay-ish in C++11 (with rval references), although it could be
>> much better, for instance, the type mangling/wrapping induced by this
>> sort of library solution always leads to awkward situations, ie,
>> 'this' pointer in a method is not an RC object anymore! Methods can't
>> give out pointers to themselves (ie, signaling events where it's
>> conventional to pass a 'sender' to the subscribers). Pretty massive
>> fail!
>
>
> Did you look into doing something like std::enable_shared_from_this? I use
> it pretty routinely in networking code (boost.asio), and while it is not as
> pretty as it could be, it does the trick.

I did. We ended up with custom solutions, tailored to take advantage
of our specific and fairly unconventional environment. Our RC is
invasive in most cases, using a duck-typed approach to the general
API.
I'm not really proud that we re-invented that wheel (among many,
because C++ offerings are generally insufficient), but it had to be
done.


More information about the Digitalmars-d mailing list