std.experimental.allocator.building_blocks.bucketizer

struct Bucketizer

Types 1

structBucketizer(Allocator, size_t min, size_t max, size_t step)

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.

Fields
Allocator[(max + 1 - min) / step] bucketsThe array of allocators is publicly available for e.g. initialization and inspection.
uint alignmentThe alignment offered is the same as `Allocator.alignment`.
Methods
private Allocator * allocatorFor(size_t n) pure nothrow @safe @nogc
size_t goodAllocSize(size_t bytes) pure nothrow @safe @nogc constRounds up to the maximum size of the bucket in which `bytes` falls.
void[] allocate(size_t bytes)Directs the call to either one of the `buckets` allocators.
bool expand(ref void[] b, size_t delta)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 step - 1]).
bool reallocate(ref void[] b, size_t size)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 step - 1]), then reallocation is in place. Otherwise, r...