How do I use the ScopedAllocator?
Yuxuan Shui via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 21 18:54:28 PDT 2016
Is it OK to use makeArray with ScopedAllocator to allocate
something with a destructor?
Because the destructor is not called when ScopedAllocator goes
out of scope. And if I manually call dispose, I get a double free
error:
struct A {
int a;
~this() nothrow {
}
}
void test(){
import std.experimental.allocator.mallocator : Mallocator;
import
std.experimental.allocator.building_blocks.scoped_allocator :
ScopedAllocator;
import std.experimental.allocator;
ScopedAllocator!Mallocator alloc;
auto b = alloc.makeArray!A(10, A(1));
auto c = alloc.makeArray!A(2, A(2));
alloc.dispose(b);
alloc.dispose(c);
}
void main() {
test();
}
More information about the Digitalmars-d
mailing list