Constructors setting up the memory structured as a free list.
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.
Deallocates b. If it's of eligible size, it's put on the free list. Otherwise, it's returned to parent.
Deallocates everything from the parent.
Returns Ternary.yes if no memory is currently allocated with this allocator, Ternary.no otherwise. This method never returns Ternary.unknown.
If n is eligible for freelisting, returns max. Otherwise, returns parent.goodAllocSize(n).
Defined if ParentAllocator defines it. Checks whether the block belongs to this allocator.
Alignment offered.
The parent allocator. Depending on whether ParentAllocator holds state or not, this is a member variable or an alias for ParentAllocator.instance.
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) );
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.