Segregator

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, the Segregator will also offer shared methods.

Members

Functions

alignedAllocate
void[] alignedAllocate(size_t , uint )

This method is defined if both allocators define it, and forwards to SmallAllocator or LargeAllocator appropriately.

alignedReallocate
bool alignedReallocate(void[] b, size_t s)

This method is defined only if at least one of the allocators defines it, and work similarly to reallocate.

allocate
void[] allocate(size_t )

The memory is obtained from SmallAllocator if s <= threshold, or LargeAllocator otherwise.

allocatorForSize
auto ref allocatorForSize()

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.

deallocate
bool deallocate(void[] b)

This function is defined only if both allocators define it, and forwards appropriately depending on b.length.

deallocateAll
bool deallocateAll()

This function is defined only if both allocators define it, and calls deallocateAll for them in turn.

empty
Ternary empty()

This function is defined only if both allocators define it, and returns the conjunction of empty calls for the two.

expand
bool expand(void[] b, size_t delta)

This method is defined only if at least one of the allocators defines it. If SmallAllocator defines expand and b.length + delta <= threshold, the call is forwarded to SmallAllocator. If LargeAllocator defines expand and b.length > threshold, the call is forwarded to LargeAllocator. Otherwise, the call returns false.

owns
Ternary owns(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.

reallocate
bool reallocate(void[] b, size_t s)

This method is defined only if at least one of the allocators defines it. If SmallAllocator defines reallocate and 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.

Mixins

__anonymous
mixin Impl!()
Undocumented in source.
__anonymous
mixin Impl!()
Undocumented in source.
__anonymous
mixin Impl!()
Undocumented in source.

Static functions

goodAllocSize
size_t goodAllocSize(size_t s)

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 define goodAllocSize, the default implementation in this module applies.)

Variables

alignment
enum uint alignment;

The alignment offered is the minimum of the two allocators' alignment.

alignment
enum uint alignment;
Undocumented in source.

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);

Meta