Allocates the requested bytes of memory with specified alignment. Directs the call to either one of the buckets allocators. Defined only if Allocator defines alignedAllocate.
Similar to reallocate, with alignment. Defined only if Allocator defines alignedReallocate.
Directs the call to either one of the buckets allocators.
This method is only defined if Allocator defines deallocate.
This method is only defined if all allocators involved define deallocateAll, and calls it for each bucket in turn. Returns true if all allocators could deallocate all.
This method allows expansion within the respective bucket range. It succeeds if both b.length and b.length + delta fall in a range of the form [min + k * step, min + (k + 1) * step - 1].
Rounds up to the maximum size of the bucket in which bytes falls.
Defined only if Allocator defines owns. Finds the owner of b and forwards the call to it.
This method allows reallocation within the respective bucket range. If both b.length and size fall in a range of the form [min + k * step, min + (k + 1) * step - 1], then reallocation is in place. Otherwise, reallocation with moving is attempted.
This method is only defined if all allocators involved define resolveInternalPointer, and tries it for each bucket in turn.
The alignment offered is the same as Allocator.alignment.
The array of allocators is publicly available for e.g. initialization and inspection.
import std.algorithm.comparison : max; import std.experimental.allocator.building_blocks.allocator_list : AllocatorList; import std.experimental.allocator.building_blocks.free_list : FreeList; import std.experimental.allocator.building_blocks.region : Region; import std.experimental.allocator.common : unbounded; import std.experimental.allocator.mallocator : Mallocator; import std.typecons : Ternary; Bucketizer!( FreeList!( AllocatorList!( (size_t n) => Region!Mallocator(max(n, 1024 * 1024))), 0, unbounded), 65, 512, 64) a; auto b = a.allocate(400); assert(b.length == 400); assert(a.owns(b) == Ternary.yes); a.deallocate(b);
A Bucketizer uses distinct allocators for handling allocations of sizes in the intervals [min, min + step - 1], [min + step, min + 2 * step - 1], [min + 2 * step, min + 3 * step - 1], ..., [max - step + 1, max].
Bucketizer holds a fixed-size array of allocators and dispatches calls to them appropriately. The size of the array is (max + 1 - min) / step, which must be an exact division.
Allocations for sizes smaller than min or larger than max are illegal for Bucketizer. To handle them separately, Segregator may be of use.