SmartRef: The Smart Pointer In D

Ola Fosheim Grøstad via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Mon Jan 23 08:38:10 PST 2017


On Saturday, 14 January 2017 at 15:41:01 UTC, Dmitry Olshansky 
wrote:
> That is C++ smart_ptr has to be atomic, while its D counter 
> part may safely be non-atomic because everything is TLS be 
> default.

I assume you mean std::shared_ptr. The reference counting 
semantics are atomic, but the I don't think the compiler is 
required to if it provably isn't shared. There are also ways to 
get around it if needed (you only need atomic count when you 
enter or leave a context, e.g. thread).

Of course, there are C++ single threaded alternatives with 
intrusive ref counting, which I believe is what D is going for. 
shared_ptr is non-intrusive (doesn't affect allocation or object 
types).


More information about the Digitalmars-d-announce mailing list