View source code
Display the source code in std/experimental/allocator/building_blocks/free_list.d from which this page was generated on github.
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 local clone.

Struct std.experimental.allocator.building_blocks.free_list.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).

struct ContiguousFreeList(ParentAllocator, ulong minSize, ulong maxSize = minSize) ;

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

NameDescription
this (buffer) Constructors setting up the memory structured as a free list.

Fields

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

Methods

NameDescription
allocate (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 (b) Deallocates b. If it's of eligible size, it's put on the free list. Otherwise, it's returned to parent.
deallocateAll () Deallocates everything from the parent.
empty () Returns Ternary.yes if no memory is currently allocated with this allocator, Ternary.no otherwise. This method never returns Ternary.unknown.
goodAllocSize (n) If n is eligible for freelisting, returns max. Otherwise, returns parent.goodAllocSize(n).
owns (b) Defined if ParentAllocator defines it. Checks whether the block belongs to this allocator.

Example

import std.experimental.allocator.building_blocks.allocator_list
    : AllocatorList;
import std.experimental.allocator.gc_allocator : GCAllocator;

import std.experimental.allocator.common : unbounded;

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

Authors

License