On 9/25/13 12:03 PM, Peter Alexander wrote:
On Sunday, 22 September 2013 at 23:49:56 UTC, Andrei Alexandrescu wrote:struct NullAllocator { enum alignment = real.alignof; enum size_t available = 0; ubyte[] allocate(size_t s) shared { return null; } bool expand(ref ubyte[] b, size_t minDelta, size_t maxDelta) shared { assert(b is null); return false; } bool reallocate(ref ubyte[] b, size_t) shared { assert(b is null); return false; } void deallocate(ubyte[] b) shared { assert(b is null); } void collect() shared { } void deallocateAll() shared { } static shared NullAllocator it; }Does the presence of "shared" indicate that all allocators must be thread-safe? Will we be able to define thread-unsafe allocators, designed for use on one thread for performance reasons?
Shared is not required. Most allocators I wrote are thread-local. I've only put "shared" there for NullAllocator, Mallocator, GCAllocator to represent in the type system a simple reality - these allocators offer a singleton that multiple threads may use simultaneously.
Andrei
