www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16250] New: GCAllocator should be at least safe, nothrow


          Issue ID: 16250
           Summary: GCAllocator should be at least  safe, nothrow
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: safe
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: greensunny12 gmail.com

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;

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


For no required shared in the GCAllocator, there is another ongoing effort: 

Jul 07 2016