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

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

struct SharedFreeList(ParentAllocator, ulong minSize, ulong maxSize = minSize, ulong approxMaxNodes = unbounded) ;

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

Fields

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

Properties

NameTypeDescription
approxMaxLength[get, set] size_tProperties for getting (and possibly setting) the approximate maximum length of a shared freelist.
max[get, set] size_tProperties 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[get, set] size_tProperties 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.

Methods

NameDescription
allocate (bytes) Standard primitives.
deallocate (b) Standard primitives.
deallocateAll () Standard primitives.
goodAllocSize (bytes) Standard primitives.
minimize () Nonstandard function that minimizes the memory usage of the freelist by freeing each element in turn. Defined only if ParentAllocator defines deallocate.
owns (b) Standard primitives.
reallocate (b, s) Standard primitives.
setBounds (newMin, 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.

Example

import std.experimental.allocator.common : chooseAtRuntime;
import std.experimental.allocator.mallocator : Mallocator;

shared SharedFreeList!(Mallocator, chooseAtRuntime, chooseAtRuntime) a;
a.setBounds(64, 128);
writeln(a.max); // 128
writeln(a.min); // 64

Example

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;
writeln(a.approxMaxLength); // 128
a.approxMaxLength = 1024;
writeln(a.approxMaxLength); // 1024
a.approxMaxLength = 1;
writeln(a.approxMaxLength); // 1

Authors

License