stdx.allocator.building_blocks.segregator
-
Declaration
structSegregator(size_t threshold, SmallAllocator, LargeAllocator);Dispatches allocations (and deallocations) between two allocators ( and ) depending on the size allocated, as follows. All allocations smaller than or equal to will be dispatched to . The others will go to .
Discussion
If both allocators are , the will also offer methods.
Examples
import stdx.allocator.building_blocks.free_list : FreeList; import stdx.allocator.gc_allocator : GCAllocator; import stdx.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); assert(b.length == 200); a.deallocate(b);
-
Declaration
enum uintalignment;The
alignmentoffered is the minimum of the two allocators'alignment. -
Declaration
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 if , or otherwise. (If one of the allocators does not define , the default implementation in this module applies.)
-
Declaration
void[]allocate(size_t);The memory is obtained from if , or otherwise.
-
Declaration
void[]alignedAllocate(size_t, uint);This method is defined if both allocators define it, and forwards to or appropriately.
-
Declaration
boolexpand(ref void[]b, size_tdelta);This method is defined only if at least one of the allocators defines it. If defines and , the call is forwarded to . If defines and , the call is forwarded to . Otherwise, the call returns .
-
Declaration
boolreallocate(ref void[]b, size_ts);This method is defined only if at least one of the allocators defines it. If defines and , the call is forwarded to . If defines and , the call is forwarded to . Otherwise, the call returns .
-
Declaration
boolalignedReallocate(ref void[]b, size_ts);This method is defined only if at least one of the allocators defines it, and work similarly to .
-
Declaration
Ternaryowns(void[]b);This method is defined only if both allocators define it. The call is forwarded to if , or otherwise.
-
Declaration
booldeallocate(void[]b);This function is defined only if both allocators define it, and forwards appropriately depending on .
-
Declaration
booldeallocateAll();This function is defined only if both allocators define it, and calls for them in turn.
-
Declaration
Ternaryempty();This function is defined only if both allocators define it, and returns the conjunction of calls for the two.
-
Declaration
ref autoallocatorForSize(size_t s)();Composite allocators involving nested instantiations of make it difficult to access individual sub-allocators stored within. simplifies the task by supplying the allocator nested inside a that is responsible for a specific size .
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);
-
Declaration
templateSegregator(Args...) if (Args.length > 3)A with more than three arguments expands to a composition of elemental s, as illustrated by the following example:
Discussion
alias A = Segregator!( n1, A1, n2, A2, n3, A3, A4 );
With this definition, allocation requests for bytes or less are directed to ; requests between and bytes (inclusive) are directed to ; requests between and bytes (inclusive) are directed to ; and requests for more than bytes are directed to . If some particular range should not be handled, may be used appropriately.Examples
import stdx.allocator.building_blocks.free_list : FreeList; import stdx.allocator.gc_allocator : GCAllocator; import stdx.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); assert(b.length == 201); a.deallocate(b);