xxxxxxxxxx
import core.memory;
import std.experimental.allocator.mallocator;
import core.lifetime;
class Bar{
}
struct Foo{
Bar bar;
this(Bar bar){
this.bar = bar;
}
}
void main(){
void[] buffer = Mallocator.instance.allocate(Foo.sizeof * 10);
scope(exit){
GC.removeRange(buffer.ptr);
Mallocator.instance.deallocate(buffer);
}
GC.addRange(buffer.ptr, Foo.sizeof);
emplace(cast(Foo*)buffer.ptr, new Bar);
GC.addRange(buffer.ptr, Foo.sizeof*2); //Overlaps previous range, is it OK?
emplace(cast(Foo*)(buffer.ptr + Foo.sizeof), new Bar);
}