AffixAllocator(Allocator, Prefix, Suffix = void);import std.experimental.allocator.mallocator : Mallocator;// One word before and after each allocation.alias A =AffixAllocator!(Mallocator, size_t, size_t);auto b = A.instance.allocate(11);A.instance.prefix(b) = 0xCAFE_BABE;A.instance.suffix(b) = 0xDEAD_BEEF;assert(A.instance.prefix(b) == 0xCAFE_BABE && A.instance.suffix(b) == 0xDEAD_BEEF);
alignment;_parent;_parent is uniformly used for accessing the parent allocator.parent();goodAllocSize(size_t);allocate(size_t);owns(void[]);expand(ref void[]b, size_tdelta);reallocate(ref void[]b, size_ts);deallocate(void[]b);deallocateAll();empty();goodAllocSize, which may use the global default). Also, the methods will be shared if the parent allocator defines them as such.instance;instance singleton is defined if and only if the parent allocator has no state and defines its ownit object.prefix(T)(T[]b);suffix(T)(T[]b);b previously allocated with this allocator.b may not be null. They are defined if and only if the corresponding affix is notvoid.b) andaffix(b) depending on the type ofb.| Argument Type | Return | Comments |
|---|---|---|
| shared(U)[] | ref shared Affix | Data is shared across threads and the affix follows suit. |
| immutable(U)[] | ref shared Affix | Although the data is immutable, the allocator "knows" the underlying memory is mutable, soimmutable is elided for the affix which is independent from the data itself. However, the result isshared becauseimmutable is implicitly shareable so multiple threads may access and manipulate the affix for the same data. |
| const(shared(U))[] | ref shared Affix | The data is always shareable across threads. Even if the data isconst, the affix is modifiable by the same reasoning as forimmutable. |
| const(U)[] | ref const Affix | The input may have originated fromU[] orimmutable(U)[], so it may be actually shared or not. Returning an unqualified affix may result in race conditions, whereas returning ashared affix may result in inadvertent sharing of mutable thread-local data across multiple threads. So the returned type is conservativelyref const. |
| U[] | ref Affix | Unqualified data has unqualified affixes. |
Preconditionb !is null andb must have been allocated with this allocator.