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).

Source: std/experimental/allocator/typed.d

Types 2

enumAllocFlag : uint

Allocation-related flags dictated by type characteristics. TypedAllocator deduces these flags from the type being allocated and uses the appropriate allocator accordingly.

_init = 0
fixedSize = 1Fixed-size allocation (unlikely to get reallocated later). Examples: `int`, `double`, any `struct` or `class` type. By default it is assumed that the allocation is variable-size, i.e. susceptible t...
hasNoIndirections = 4The type being allocated embeds no pointers. Examples: `int`, `int[]`, Tuple!(int). The implicit conservative assumption is that the type has members with indirections so it needs to be scanned if ...
immutableShared = 8By default it is conservatively assumed that allocated memory may be `cast` to `shared`, passed across threads, and deallocated in a different thread than the one that allocated it. If that's not t...
threadLocal = 16ditto
structTypedAllocator(PrimaryAllocator, Policies...)

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

PrimaryAllocatorThe default allocator.
PoliciesZero or more pairs consisting of an AllocFlag and an allocator type.
Methods
private 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)()ditto
uint 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)Ditto
T[] makeArray(T, R)(R range) if (isInputRange!R)Ditto
bool 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)Ditto
bool expandArray(T, R)(ref T[] array, R range) if (isInputRange!R)Ditto
bool 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))Ditto
void dispose(T)(T[] array)Ditto
Nested Templates
Stride2(T...)