Given flags as a combination of AllocFlag values, or a type T, returns the allocator that's a closest fit in capabilities.
Destroys and then deallocates (using allocatorFor!T) the object pointed to by a pointer, the class object referred to by a class or interface reference, or an entire array. It is assumed the respective entities had been allocated with the same allocator.
Grows array by appending delta more elements. The needed memory is allocated using the same allocator that was used for the array type. The extra elements added are either default-initialized, filled with copies of init, or initialized with values fetched from range.
Dynamically allocates (using the appropriate allocator chosen with allocatorFor!T) and then creates in the memory allocated an object of type T, using args (if any) for its initialization. Initialization occurs in the memory allocated and is otherwise semantically the same as T(args). (Note that using make!(T[]) creates a pointer to an (empty) array of Ts, not an array. To allocate and initialize an array, use makeArray!T described below.)
Create an array of T with length elements. The array is either default-initialized, filled with copies of init, or initialized with values fetched from range.
Shrinks an array by delta elements using allocatorFor!(T[]).
Given a type T, returns its allocation-related flags as a combination of AllocFlag values.
The default allocator.
Zero or more pairs consisting of an AllocFlag and an allocator type.
import stdx.allocator.gc_allocator : GCAllocator; import stdx.allocator.mallocator : Mallocator; import stdx.allocator.mmap_allocator : MmapAllocator; alias MyAllocator = TypedAllocator!(GCAllocator, AllocFlag.fixedSize | AllocFlag.threadLocal, Mallocator, AllocFlag.fixedSize | AllocFlag.threadLocal | AllocFlag.hasNoIndirections, MmapAllocator, ); MyAllocator a; auto b = a.allocatorFor!0(); static assert(is(typeof(b) == GCAllocator)); enum f1 = AllocFlag.fixedSize | AllocFlag.threadLocal; auto c = a.allocatorFor!f1(); static assert(is(typeof(c) == Mallocator)); enum f2 = AllocFlag.fixedSize | AllocFlag.threadLocal; static assert(is(typeof(a.allocatorFor!f2()) == Mallocator)); // Partial match enum f3 = AllocFlag.threadLocal; static assert(is(typeof(a.allocatorFor!f3()) == Mallocator)); int* p = a.make!int; scope(exit) a.dispose(p); int[] arr = a.makeArray!int(42); scope(exit) a.dispose(arr); assert(a.expandArray(arr, 3)); assert(a.shrinkArray(arr, 4));
TypedAllocator acts like a chassis on which several specialized allocators can be assembled. To let the system make a choice about a particular kind of allocation, use Default for the respective parameters.
There is a hierarchy of allocation kinds. When an allocator is implemented for a given combination of flags, it is used. Otherwise, the next down the list is chosen.