Segregator

A Segregator with more than three arguments expands to a composition of elemental Segregators, 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.

  1. struct Segregator(size_t threshold, SmallAllocator, LargeAllocator)
  2. template Segregator(Args...)
    template Segregator (
    Args...
    ) if (
    Args.length > 3
    ) {}

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);
assert(b.length == 201);
a.deallocate(b);

Meta