std.experimental.allocator.typed
This module defines TypedAllocator, a statically-typed allocator that aggregates multiple untyped allocators and uses them depending on the static properties of the types allocated. For example, distinct allocators may be used for thread-local vs. thread-shared data, or for fixed-size data (struct, class objects) vs. resizable data (arrays).
Types 2
Allocation-related flags dictated by type characteristics. TypedAllocator deduces these flags from the type being allocated and uses the appropriate allocator accordingly.
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.
Parameters
PrimaryAllocator | The default allocator. |
Policies | Zero or more pairs consisting of an AllocFlag and an allocator type. |
bool match(uint have, uint want)auto ref allocatorFor(uint flags)()Given `flags` as a combination of `AllocFlag` values, or a type `T`, returns the allocator that's a closest fit in capabilities.auto ref allocatorFor(T)()dittouint type2flags(T)()Given a type `T`, returns its allocation-related flags as a combination of `AllocFlag` values.auto make(T, A...)(auto ref A args)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. In...T[] makeArray(T)(size_t length)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`.T[] makeArray(T)(size_t length, auto ref T init)Dittobool expandArray(T)(ref T[] array, size_t delta)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, ...bool expandArray(T)(T[] array, size_t delta, auto ref T init)Dittobool expandArray(T, R)(ref T[] array, R range) if (isInputRange!R)Dittobool shrinkArray(T)(ref T[] arr, size_t delta)Shrinks an array by `delta` elements using `allocatorFor!(T[])`.void dispose(T)(T * p)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 ...void dispose(T)(T p) if (is(T == class) || is(T == interface))Dittovoid dispose(T)(T[] array)DittoStride2(T...)