SharedFreeList

FreeList shared across threads. Allocation and deallocation are lock-free. The parameters have the same semantics as for FreeList.

expand is defined to forward to ParentAllocator.expand (it must be also shared).

struct SharedFreeList (
ParentAllocator
size_t minSize
size_t maxSize = minSize
size_t approxMaxNodes = unbounded
) {}

Members

Aliases

approxMaxLength
alias approxMaxLength = approxMaxNodes
Undocumented in source.
max
alias max = maxSize
Undocumented in source.
min
alias min = minSize
Undocumented in source.
parent
alias parent = ParentAllocator.instance
Undocumented in source.

Functions

allocate
void[] allocate(size_t bytes)
deallocate
bool deallocate(void[] b)
deallocateAll
bool deallocateAll()
goodAllocSize
size_t goodAllocSize(size_t bytes)

Standard primitives.

minimize
void minimize()

Nonstandard function that minimizes the memory usage of the freelist by freeing each element in turn. Defined only if ParentAllocator defines deallocate.

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

Standard primitives.

setBounds
void setBounds(size_t low, size_t high)
Undocumented in source. Be warned that the author may not have intended to support it.
setBounds
void setBounds(size_t newMin, size_t newMax)

Properties for getting (and possibly setting) the bounds. Setting bounds is allowed only once , and before any allocation takes place. Otherwise, the primitives have the same semantics as those of FreeList.

Properties

approxMaxLength
size_t approxMaxLength [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
approxMaxLength
size_t approxMaxLength [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.
approxMaxLength
size_t approxMaxLength [@property getter]

Properties for getting (and possibly setting) the approximate maximum length of a shared freelist.

max
size_t max [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
max
size_t max [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.
max
size_t max [@property getter]

Properties for getting (and possibly setting) the bounds. Setting bounds is allowed only once , and before any allocation takes place. Otherwise, the primitives have the same semantics as those of FreeList.

min
size_t min [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
min
size_t min [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.
min
size_t min [@property getter]

Properties for getting (and possibly setting) the bounds. Setting bounds is allowed only once , and before any allocation takes place. Otherwise, the primitives have the same semantics as those of FreeList.

Variables

alignment
enum uint alignment;

Standard primitives.

parent
ParentAllocator parent;

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

Examples

import stdx.allocator.common : chooseAtRuntime;
import stdx.allocator.mallocator : Mallocator;

shared SharedFreeList!(Mallocator, chooseAtRuntime, chooseAtRuntime) a;
a.setBounds(64, 128);
assert(a.max == 128);
assert(a.min == 64);
import stdx.allocator.common : chooseAtRuntime;
import stdx.allocator.mallocator : Mallocator;

shared SharedFreeList!(Mallocator, 50, 50, chooseAtRuntime) a;
// Set the maxSize first so setting the minSize doesn't throw
a.approxMaxLength = 128;
assert(a.approxMaxLength  == 128);
a.approxMaxLength = 1024;
assert(a.approxMaxLength  == 1024);
a.approxMaxLength = 1;
assert(a.approxMaxLength  == 1);

Meta