stdx.allocator.building_blocks.bucketizer
-
Declaration
structBucketizer(Allocator, size_t min, size_t max, size_t step);A uses distinct allocators for handling allocations of sizes in the intervals , , , , .
Discussion
holds a fixed-size array of allocators and dispatches calls to them appropriately. The size of the array is , which must be an exact division.
Allocations for sizes smaller than or larger than are illegal for . To handle them separately, may be of use.Examples
import std.algorithm.comparison : max; import stdx.allocator.building_blocks.allocator_list : AllocatorList; import stdx.allocator.building_blocks.free_list : FreeList; import stdx.allocator.building_blocks.region : Region; import stdx.allocator.common : unbounded; import stdx.allocator.mallocator : Mallocator; import stdx.allocator.internal : 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); void[] p; a.deallocate(b);
-
Declaration
Allocator[(max + 1 - min) / step]buckets;The array of allocators is publicly available for e.g. initialization and inspection.
-
Declaration
enum uintalignment;The
alignmentoffered is the same as . -
Declaration
const size_tgoodAllocSize(size_tbytes);Rounds up to the maximum size of the bucket in which falls.
-
Declaration
void[]allocate(size_tbytes);Directs the call to either one of the allocators.
-
Declaration
void[]alignedAllocate(size_tbytes, uinta);Directs the call to either one of the allocators. Defined only if
Allocatordefines.alignedAllocate -
Declaration
boolexpand(ref void[]b, size_tdelta);This method allows expansion within the respective bucket range. It succeeds if both and fall in a range of the form .
-
Declaration
boolreallocate(ref void[]b, size_tsize);This method allows reallocation within the respective bucket range. If both and fall in a range of the form , then reallocation is in place. Otherwise, reallocation with moving is attempted.
-
Declaration
boolalignedReallocate(ref void[]b, size_tsize, uinta);Similar to
reallocate, with alignment. Defined only ifAllocatordefines.alignedReallocate -
Declaration
Ternaryowns(void[]b);Defined only if
Allocatordefines. Finds the owner ofownsand forwards the call to it.b -
Declaration
booldeallocate(void[]b);This method is only defined if defines .
-
Declaration
booldeallocateAll();This method is only defined if all allocators involved define , and calls it for each bucket in turn. Returns
trueif all allocators could deallocate all. -
Declaration
TernaryresolveInternalPointer(const void*p, ref void[]result);This method is only defined if all allocators involved define , and tries it for each bucket in turn.