The OpenD Programming Language

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

Members

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 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]
size_t approxMaxLength [@property setter]

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

max
size_t max [@property getter]
size_t max [@property setter]

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]
size_t min [@property setter]

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 std.experimental.allocator.common : chooseAtRuntime;
import std.experimental.allocator.mallocator : Mallocator;

shared SharedFreeList!(Mallocator, chooseAtRuntime, chooseAtRuntime) a;
a.setBounds(64, 128);
assert(a.max == 128);
assert(a.min == 64);
import std.experimental.allocator.common : chooseAtRuntime;
import std.experimental.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