Allocator troubles

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 17 05:31:40 PDT 2016


On 7/16/16 12:45 PM, Luís Marques wrote:
> 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?

I don't know yet. Thinking of it. -- Andrei



More information about the Digitalmars-d mailing list