ContiguousFreeList

Free list built on top of exactly one contiguous block of memory. The block is assumed to have been allocated with ParentAllocator, and is released in ContiguousFreeList's destructor (unless ParentAllocator is NullAllocator).

ContiguousFreeList has most advantages of FreeList but fewer disadvantages. It has better cache locality because items are closer to one another. It imposes less fragmentation on its parent allocator.

The disadvantages of ContiguousFreeList over FreeList are its pay upfront model (as opposed to FreeList's pay-as-you-go approach), and a hard limit on the number of nodes in the list. Thus, a large number of long- lived objects may occupy the entire block, making it unavailable for serving allocations from the free list. However, an absolute cap on the free list size may be beneficial.

The options minSize == unbounded and maxSize == unbounded are not available for ContiguousFreeList.

Constructors

this
this(ubyte[] buffer)
this(ParentAllocator parent, ubyte[] buffer)
this(size_t bytes)
this(ParentAllocator parent, size_t bytes)
this(size_t bytes, size_t max)
this(ParentAllocator parent, size_t bytes, size_t max)
this(size_t bytes, size_t min, size_t max)
this(ParentAllocator parent, size_t bytes, size_t min, size_t max)

Constructors setting up the memory structured as a free list.

Members

Aliases

Impl
alias Impl = FreeList!(NullAllocator, minSize, maxSize)
Undocumented in source.
Node
alias Node = Impl.Node
Undocumented in source.
SParent
alias SParent = StatsCollector!(ParentAllocator, Options.bytesUsed)
Undocumented in source.

Functions

allocate
void[] allocate(size_t n)

Allocate n bytes of memory. If n is eligible for freelist and the freelist is not empty, pops the memory off the free list. In all other cases, uses the parent allocator.

deallocate
bool deallocate(void[] b)

Deallocates b. If it's of eligible size, it's put on the free list. Otherwise, it's returned to parent.

deallocateAll
bool deallocateAll()

Deallocates everything from the parent.

empty
Ternary empty()

Returns Ternary.yes if no memory is currently allocated with this allocator, Ternary.no otherwise. This method never returns Ternary.unknown.

goodAllocSize
size_t goodAllocSize(size_t n)

If n is eligible for freelisting, returns max. Otherwise, returns parent.goodAllocSize(n).

owns
Ternary owns(void[] b)

Defined if ParentAllocator defines it. Checks whether the block belongs to this allocator.

Manifest constants

unchecked
enum unchecked;
Undocumented in source.

Variables

alignment
enum uint alignment;

Alignment offered.

allocated
size_t allocated;
Undocumented in source.
fl
FreeList!(NullAllocator, minSize, maxSize) fl;
Undocumented in source.
parent
SParent parent;

The parent allocator. Depending on whether ParentAllocator holds state or not, this is a member variable or an alias for ParentAllocator.instance.

support
void[] support;
Undocumented in source.

Examples

import stdx.allocator.building_blocks.allocator_list
    : AllocatorList;
import stdx.allocator.mallocator : Mallocator;

import stdx.allocator.common : unbounded;

alias ScalableFreeList = AllocatorList!((n) =>
    ContiguousFreeList!(Mallocator, 0, unbounded)(4096)
);

Meta