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.segregator
- structSegregator(size_t threshold, SmallAllocator, LargeAllocator);
- Dispatches allocations (and deallocations) between two allocators (SmallAllocator and LargeAllocator) depending on the size allocated, as follows. All allocations smaller than or equal to threshold will be dispatched to SmallAllocator. The others will go to LargeAllocator.If both allocators are shared, theSegregatorwill also offer shared methods.Examples:import std.experimental.allocator.building_blocks.free_list : FreeList; import std.experimental.allocator.gc_allocator : GCAllocator; import std.experimental.allocator.mallocator : Mallocator; alias A = Segregator!( 1024 * 4, Segregator!( 128, FreeList!(Mallocator, 0, 128), GCAllocator), Segregator!( 1024 * 1024, Mallocator, GCAllocator) ); A a; auto b = a.allocate(200); writeln(b.length); // 200 a.deallocate(b); - enum uintalignment;
- The alignment offered is the minimum of the two allocators' alignment.
- static size_tgoodAllocSize(size_ts);
- This method is defined only if at least one of the allocators defines it. The good allocation size is obtained from SmallAllocator if s <= threshold, or LargeAllocator otherwise. (If one of the allocators does not definegoodAllocSize, the default implementation in this module applies.)
- void[]allocate(size_t);
- The memory is obtained from SmallAllocator if s <= threshold, or LargeAllocator otherwise.
- void[]alignedAllocate(size_t, uint);
- This method is defined if both allocators define it, and forwards to SmallAllocator or LargeAllocator appropriately.
- boolexpand(ref void[]b, size_tdelta);
- This method is defined only if at least one of the allocators defines it. If SmallAllocator definesexpandand b.length + delta <= threshold, the call is forwarded to SmallAllocator. If LargeAllocator definesexpandand b.length > threshold, the call is forwarded to LargeAllocator. Otherwise, the call returns false.
- boolreallocate(ref void[]b, size_ts);
- This method is defined only if at least one of the allocators defines it. If SmallAllocator definesreallocateand b.length <= threshold && s <= threshold, the call is forwarded to SmallAllocator. If LargeAllocator defines expand and b.length > threshold && s > threshold, the call is forwarded to LargeAllocator. Otherwise, the call returns false.
- boolalignedReallocate(ref void[]b, size_ts, uinta);
- This method is defined only if at least one of the allocators defines it, and work similarly to reallocate.
- Ternaryowns(void[]b);
- This method is defined only if both allocators define it. The call is forwarded to SmallAllocator if b.length <= threshold, or LargeAllocator otherwise.
- booldeallocate(void[]b);
- This function is defined only if both allocators define it, and forwards appropriately depending onb.length.
- booldeallocateAll();
- This function is defined only if both allocators define it, and callsdeallocateAllfor them in turn.
- Ternaryempty();
- This function is defined only if both allocators define it, and returns the conjunction ofemptycalls for the two.
- ref autoallocatorForSize(size_t s)();
- Composite allocators involving nested instantiations of Segregator make it difficult to access individual sub-allocators stored within. allocatorForSize simplifies the task by supplying the allocator nested inside a Segregator that is responsible for a specific size s.Example alias A = Segregator!(300, Segregator!(200, A1, A2), A3); A a; static assert(typeof(a.allocatorForSize!10) == A1); static assert(typeof(a.allocatorForSize!250) == A2); static assert(typeof(a.allocatorForSize!301) == A3); 
 
- templateSegregator(Args...) if (Args.length > 3)
- ASegregatorwith more than three arguments expands to a composition of elementalSegregators, as illustrated by the following example:alias A = Segregator!( n1, A1, n2, A2, n3, A3, A4 ); With this definition, allocation requests for n1 bytes or less are directed to A1; requests between n1 + 1 and n2 bytes (inclusive) are directed to A2; requests between n2 + 1 and n3 bytes (inclusive) are directed to A3; and requests for more than n3 bytes are directed to A4. If some particular range should not be handled, NullAllocator may be used appropriately.Examples:import std.experimental.allocator.building_blocks.free_list : FreeList; import std.experimental.allocator.gc_allocator : GCAllocator; import std.experimental.allocator.mallocator : Mallocator; alias A = Segregator!( 128, FreeList!(Mallocator, 0, 128), 1024 * 4, GCAllocator, 1024 * 1024, Mallocator, GCAllocator ); A a; auto b = a.allocate(201); writeln(b.length); // 201 a.deallocate(b); 
Copyright © 1999-2025 by the D Language Foundation | Page generated by
Ddoc on Mon Mar 31 10:28:19 2025