Surprising behaviour of std.experimental.allocator

Elronnd elronnd at elronnd.net
Thu Dec 24 23:46:58 UTC 2020


On Thursday, 24 December 2020 at 16:12:31 UTC, Saurabh Das wrote:
> This causes a segfault when run with rdmd -gx:
> *snip*

First, here's a reduced version:

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 = FallbackAllocator!(
				AllocatorList!(n => Region!Mallocator(MB)),
				Mallocator);
		auto alloc1 = allocatorObject(Alloc1());

		GC.collect;
		alloc1.allocate(MB);
	}
	
	writeln(5); // this never gets printed; segfault happens upon 
exiting the above scope
}


I'm not 100% sure where the segfault comes from--though I think 
it's a problem with AllocatorList--but as a workaround, try 
replacing ‘AllocatorList!(n => Region!Mallocator(MB))’ with 
‘AllocatorList!(n => Region!Mallocator(MB), NullAllocator)’.


More information about the Digitalmars-d-learn mailing list