Allocator troubles
Luís Marques via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jul 16 09:45:18 PDT 2016
On Saturday, 16 July 2016 at 16:19:11 UTC, Andrei Alexandrescu
wrote:
> Found the problem. Currently allocatorObject allocates the
> CAllocatorImpl object (interface implementation) straight
> inside the given allocator, in an ouroboros fashion.
> Subsequently, deallocateAll deallocates he CAllocatorImpl
> itself.
>
> CAllocatorImpl!(A, Yes.indirect) allocatorObject(A)(A* pa)
> {
> assert(pa);
> import std.conv : emplace;
> auto state = pa.allocate(stateSize!(CAllocatorImpl!(A,
> Yes.indirect)));
> import std.traits : hasMember;
> static if (hasMember!(A, "deallocate"))
> {
> scope(failure) pa.deallocate(state);
> }
> return emplace!(CAllocatorImpl!(A, Yes.indirect))
> (state, pa);
> }
What's the solution? I would say the solution is to use
theAllocator instead, to allocate the CAllocatorImpl. Or maybe a
template alias parameter that defaults to theAllocator?
More information about the Digitalmars-d
mailing list