Bug 16250 – GCAllocator should be at least @safe, nothrow
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-07-07T22:18:00Z
Last change time
2016-08-31T09:29:28Z
Keywords
pull, safe
Assigned to
nobody
Creator
greensunny12
Comments
Comment #0 by greensunny12 — 2016-07-07T22:18:19Z
A common pattern for future APIs would be to allow to pass-in a custom Allocator and have @safe and nothrow code if the GCAllocator was used. Ideally I hope that the language might ease the use of custom allocators, but being conveniently able to switch between safe and non-safe fast code would be a good start. See e.g. this simple test for an example:
nothrow unittest
{
import std.experimental.allocator: dispose, makeArray;
import std.experimental.allocator.gc_allocator: GCAllocator;
auto Allocator = GCAllocator.instance;
auto safeFun() @safe
{
int[] arr = Allocator.makeArray!int(2);
assert(arr == [0, 0]);
return arr;
}
Allocator.dispose(safeFun());
}
Imho this test could also be `pure`, but that's not really important there .
There's is already an ongoing PR, but that lost its motion and needs to be revived.
https://github.com/dlang/phobos/pull/3891
For no required shared in the GCAllocator, there is another ongoing effort:
https://github.com/dlang/phobos/pull/4288