www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - GC.addRange multiple times

Is it valid if I call GC.addRange with same or overlaping range?
Example:

https://run.dlang.io/is/a5a0Ag

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);
}
Feb 03 2021