FYI - mo' work on std.allocator

Brian Schott via Digitalmars-d digitalmars-d at puremagic.com
Sat Apr 26 23:13:21 PDT 2014


On Sunday, 27 April 2014 at 05:43:07 UTC, Andrei Alexandrescu 
wrote:
> Added SbrkRegion, SimpleBlocklist, and Blocklist.
>
> http://erdani.com/d/phobos-prerelease/std_allocator.html#.SbrkRegion
> http://erdani.com/d/phobos-prerelease/std_allocator.html#.SimpleBlocklist
> http://erdani.com/d/phobos-prerelease/std_allocator.html#.Blocklist
>
> https://github.com/andralex/phobos/blob/allocator/std/allocator.d
>
> Destruction is as always welcome. I plan to get into tracing 
> tomorrow morning.
>
>
> Andrei

There are quite a few places where functions could be marked 
pure, nothrow, @safe, or @trusted that have not been. I have a 
pull request open for many of these.

I also have a feature request. I think something like this should 
be added to std.allocator:

/**
  * Shortcut that encapsulates a cast and a call to emplace()
  * Params:
  * a = the allocator to use
  * args = the arguments to $(D T)'s constructor
  * Returns: a pointer to an instance of $(D T).
  */
T* allocate(T, Allocator, Args...)(auto ref Allocator a, auto ref 
Args args)
     @trusted if (is (T == struct))
{
     import std.conv : emplace;
     void[] mem = a.allocate(T.sizeof);
     return emplace(cast(T*) mem.ptr, args);
}

The allocate-cast-initialize pattern is incredibly common in the 
code that I've written using allocators so far and I'd like it to 
be in Phobos so that it does not need to be re-implemented 
everywhere.


More information about the Digitalmars-d mailing list