Surprising behaviour of std.experimental.allocator

Saurabh Das saurabh.das at gmail.com
Fri Dec 25 05:01:41 UTC 2020


On Thursday, 24 December 2020 at 23:58:45 UTC, Elronnd wrote:
> On Thursday, 24 December 2020 at 23:46:58 UTC, Elronnd wrote:
>> reduced version:
>
> Further reduction: Alloc1 can just be ‘AllocatorList!(n => 
> Region!Mallocator(MB))’.

Thank you for the reduced test case.

A small change to the test case seems to work in all the cases 
I've tested so far, maybe it can help diagnose the issue. If we 
use a pointer to construct the allocator, it seems to work fine:

void main() {
         import std.experimental.allocator: allocatorObject, 
expandArray;
         import 
std.experimental.allocator.building_blocks.allocator_list: 
AllocatorList;
         import std.experimental.allocator.building_blocks.region: 
Region;
         import 
std.experimental.allocator.building_blocks.fallback_allocator: 
FallbackAllocator;
         import std.experimental.allocator.mallocator: Mallocator;
         import core.memory: GC;
         import std.stdio;

         enum MB = 1024 * 1024;
         {
                 alias Alloc1 = AllocatorList!(n => 
Region!Mallocator(MB));
                 auto a1 = Alloc1();
                 auto alloc1 = allocatorObject(&a1);

                 GC.collect;
                 alloc1.allocate(MB);
         }

         writeln(5); // this never gets printed; segfault happens 
upon exiting the above scope
}



More information about the Digitalmars-d-learn mailing list