On Monday, 9 May 2016 at 04:50:59 UTC, Danni Coy wrote:
It seems to me, that std.experimental.allocator should work
with @nogc annotated functions if none of the allocators being
used are the gcallocator, though it's not at all clear to me
how this would work.
Are there plans for this?
It already mostly works in @nogc block:
- Mallocator and AlignedMallocator are @nogc.
- make() dispose(), shrinkArray(), etc are templatized function
so they infer @nogc.
- higher level blocks also infer @nogc.
example:
----
import std.experimental.allocator;
import std.experimental.allocator.mallocator;
import std.experimental.allocator.building_blocks.free_list;
struct Foo{}
void main(string[] args) @nogc
{
Foo* foo = Mallocator.instance.make!Foo;
Mallocator.instance.dispose(foo);
uint[] arr;
arr = Mallocator.instance.makeArray!uint(8);
Mallocator.instance.shrinkArray(arr,1);
Mallocator.instance.dispose(arr);
FreeList!(Mallocator,0,size_t.sizeof) fl;
auto p = fl.allocate(8);
fl.deallocate(p);
}
----
Initially it was not the case but it's been done latest months,
e.g in this PR:
https://github.com/dlang/phobos/pull/3856