Report a bug
		
				If you spot a problem with this page, click here to create a Bugzilla issue.
		
			Improve this page
		
			Quickly fork, edit online, and submit a pull request for this page.
			Requires a signed-in GitHub account. This works well for small changes.
			If you'd like to make larger changes you may want to consider using
			a local clone.
		
	std.experimental.allocator.building_blocks.bucketizer
- structBucketizer(Allocator, size_t min, size_t max, size_t step);
- ABucketizeruses 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].Bucketizerholds 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 forBucketizer. To handle them separately, Segregator may be of use.Examples: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); writeln(b.length); // 400 writeln(a.owns(b)); // Ternary.yes a.deallocate(b); - Allocator[(max + 1 - min) / step]buckets;
- The array of allocators is publicly available for e.g. initialization and inspection.
- enum uintalignment;
- The alignment offered is the same as Allocator.alignment.
- const pure nothrow @nogc @safe size_tgoodAllocSize(size_tbytes);
- Rounds up to the maximum size of the bucket in whichbytesfalls.
- void[]allocate(size_tbytes);
- Directs the call to either one of the buckets allocators.
- void[]alignedAllocate(size_tbytes, uintalignment);
- Allocates the requestedbytesof memory with specifiedalignment. Directs the call to either one of the buckets allocators. Defined only if Allocator definesalignedAllocate.
- boolexpand(ref void[]b, size_tdelta);
- This method allows expansion within the respective bucket range. It succeeds if bothb.length and b.length + delta fall in a range of the form [min + k * step, min + (k + 1) * step - 1].
- boolreallocate(ref void[]b, size_tsize);
- This method allows reallocation within the respective bucket range. If bothb.length andsizefall 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.
- boolalignedReallocate(ref void[]b, size_tsize, uinta);
- Similar to reallocate, with alignment. Defined only if Allocator definesalignedReallocate.
- Ternaryowns(void[]b);
- Defined only if Allocator definesowns. Finds the owner ofband forwards the call to it.
- booldeallocate(void[]b);
- This method is only defined if Allocator definesdeallocate.
- booldeallocateAll();
- 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.
- TernaryresolveInternalPointer(const void*p, ref void[]result);
- This method is only defined if all allocators involved define resolveInternalPointer, and tries it for each bucket in turn.
 
Copyright © 1999-2024 by the D Language Foundation | Page generated by
Ddoc on (no date time)