std.experimental.allocator.building_blocks.allocator_list

Types 2

structAllocatorList(Factory, BookkeepingAllocator = GCAllocator)

Given an object factory of type Factory or a factory function factoryFunction, and optionally also BookkeepingAllocator as a supplemental allocator for bookkeeping, AllocatorList creates an allocator that lazily creates as many allocators are needed for satisfying client allocation requests.

An embedded list builds a most-recently-used strategy: the most recent allocators used in calls to either allocate, owns (successful calls only), or deallocate are tried for new allocations in order of their most recent use. Thus, although core operations take in theory k time for k allocators in current use, in many workloads the factor is sublinear. Details of the actual strategy may change in future releases.

AllocatorList is primarily intended for coarse-grained handling of allocators, i.e. the number of allocators in the list is expected to be relatively small compared to the number of allocations handled by each allocator. However, the per-allocator overhead is small so using AllocatorList with a large number of allocators should be satisfactory as long as the most-recently-used strategy is fast enough for the application.

AllocatorList makes an effort to return allocated memory back when no longer used. It does so by destroying empty allocators. However, in order to avoid thrashing (excessive creation/destruction of allocators under certain use patterns), it keeps unused allocators for a while.

The shared version of AllocatorList is SharedAllocatorList, which has identical semantics to its single-threaded version. Both BookkeepingAllocator and Allocator provided by factoryFunction must be shared, in order to ensure corectness.

Parameters

factoryFunctionA function or template function (including function literals). New allocators are created by calling factoryFunction(n) with strictly positive numbers n. Delegates that capture their enviroment are not created amid concerns regarding garbage creation for the environment. When the factory needs state, a Factory object should be used.
BookkeepingAllocatorAllocator used for storing bookkeeping data. The size of bookkeeping data is proportional to the number of allocators. If BookkeepingAllocator is NullAllocator, then AllocatorList is "ouroboros-style", i.e. it keeps the bookkeeping data in memory obtained from the allocators themselves. Note that for ouroboros-style management, the size n passed to make will be occasionally different from the size requested by client code.
FactoryType of a factory object that returns new allocators on a need basis. For an object sweatshop of type Factory, sweatshop(n) should return an allocator able to allocate at least n bytes (i.e. Factory must define opCall(size_t) to return an allocator object). Usually the capacity of allocators created should be much larger than n such that an allocator can be used for many subsequent allocations. n is passed only to ensure the minimum necessary for the next allocation. The factory object is allowed to hold state, which will be stored inside AllocatorList as a direct public member called factory.
Fields
private is(BookkeepingAllocator == NullAllocator) ouroboros
private Node[] allocators
private Node * root
uint alignmentThe alignment offered.
Methods
void[] allocate(size_t s)Allocate a block of size `s`. First tries to allocate from the existing list of already-created allocators. If neither can satisfy the request, creates a new allocator by calling `make(s)` and dele...
private void moveAllocators(void[] newPlace)
Ternary empty() pure nothrow @safe @nogc constReturns `Ternary.yes` if no allocators are currently active, `Ternary.no` otherwise. This methods never returns `Ternary.unknown`.
Nested Templates
Node
structSharedAllocatorList(Factory, BookkeepingAllocator = GCAllocator)

Ditto

Fields
AllocatorList!(Factory, BookkeepingAllocator) impl
impl.alignment alignmentThe alignment offered.
Methods
T assumeUnshared(T)(ref shared T val) ref @trusted @nogc pure nothrow

Templates 2

tmplAllocatorList(alias factoryFunction, BookkeepingAllocator = GCAllocator)

Ditto

Types
struct Factory
tmplSharedAllocatorList(alias factoryFunction, BookkeepingAllocator = GCAllocator)

Ditto

Types
struct Factory