Surprising behaviour of std.experimental.allocator
Saurabh Das
saurabh.das at gmail.com
Thu Dec 24 16:12:31 UTC 2020
This causes a segfault when run with rdmd -gx:
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;
{
alias Alloc1 = FallbackAllocator!(
AllocatorList!(n => Region!Mallocator(1024*1024)),
Mallocator);
auto alloc1 = allocatorObject(Alloc1());
for (int ttt=0; ttt<10; ++ttt)
{
import std.stdio : writeln;
writeln(ttt);
import core.memory : GC;
auto p = alloc1.allocate(60*1024);
assert(p.length == 60*1024);
auto p2 = alloc1.allocate(3*1024*1024);
assert(p2.length == 3*1024*1024);
GC.collect();
alloc1.expandArray(p, 120*1024); // Segfault here
}
}
}
(Tested on DMD 2.094.2 and on https://run.dlang.io/is/p0FsOQ)
If the "GC.collect()" line is commented out, it works somehow.
Please help me understand why this is happening. This is a very
reduced example of an issue I am facing.
Thank You,
Saurabh
More information about the Digitalmars-d-learn
mailing list