automem v0.0.7 - C++ style smart pointers using std.experimental.allocator
Kagamin via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Mon Apr 17 06:21:50 PDT 2017
On Wednesday, 12 April 2017 at 13:32:36 UTC, Stanislav Blinov
wrote:
> Syntax is not the core of the issue, it's not about just
> marking a destructor as shared. Making RefCounted itself shared
> would require implementing some form of synchronization of all
> the 'dereference' operations, including assignments. I.e. if we
> have some shared(RefCounted!T) ptr, what should happen when two
> threads simultaneously attempt to do ptr =
> shared(RefCounted!T)(someNewValue) ? Should a library
> implementation even consider this? Or should such
> synchronization be left to client's care? It seems like in this
> regard shared(RefCounted!T) would be no different from
> shared(T*), which brings me to the next point.
If we can control memory layout, we can do what shared_ptr does
and couple the reference counter with the object, then we can
have just one pointer:
struct RefCounted(T)
{
struct Wrapper
{
int count;
T payload;
}
Wrapper* payload;
}
More information about the Digitalmars-d-announce
mailing list