stdx.allocator.building_blocks.bucketizer
-
Declaration
struct
Bucketizer
(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 uint
alignment
;The
alignment
offered is the same as . -
Declaration
const size_t
goodAllocSize
(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
Allocator
defines
.alignedAllocate
-
Declaration
bool
expand
(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
bool
reallocate
(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
bool
alignedReallocate
(ref void[]b
, size_tsize
, uinta
);Similar to
reallocate
, with alignment. Defined only ifAllocator
defines
.alignedReallocate
-
Declaration
Ternary
owns
(void[]b
);Defined only if
Allocator
defines
. Finds the owner ofowns
and forwards the call to it.b
-
Declaration
bool
deallocate
(void[]b
);This method is only defined if defines .
-
Declaration
bool
deallocateAll
();This method is only defined if all allocators involved define , and calls it for each bucket in turn. Returns
true
if all allocators could deallocate all. -
Declaration
Ternary
resolveInternalPointer
(const void*p
, ref void[]result
);This method is only defined if all allocators involved define , and tries it for each bucket in turn.