std.experimental.allocator.building_blocks.fallback_allocator
struct FallbackAllocator
Types 1
structFallbackAllocator(Primary, Fallback)
FallbackAllocator is the allocator equivalent of an "or" operator in algebra. An allocation request is first attempted with the Primary allocator. If that returns null, the request is forwarded to the Fallback allocator. All other requests are dispatched appropriately to one of the two allocators.
In order to work, FallbackAllocator requires that Primary defines the owns method. This is needed in order to decide which allocator was responsible for a given allocation.
FallbackAllocator is useful for fast, special-purpose allocators backed up by general-purpose allocators. The example below features a stack region backed up by the GCAllocator.
Fields
uint alignmentThe alignment offered is the minimum of the two allocators' alignment.Methods
void[] allocate(size_t s)Allocates memory trying the primary allocator first. If it returns null, the fallback allocator is tried.Functions 2
fn
FallbackAllocator!(Primary, Fallback) fallbackAllocator(Primary, Fallback)(auto ref Primary p, auto ref Fallback f)Convenience function that uses type deduction to return the appropriate `FallbackAllocator` instance. To initialize with allocators that don't have state, use their `it` static member.