The OpenD Programming Language

ThreadLocal

Stores an allocator object in thread-local storage (i.e. non-shared D global). ThreadLocal!A is a subtype of A so it appears to implement A's allocator primitives.

A must hold state, otherwise ThreadLocal!A refuses instantiation. This means e.g. ThreadLocal!Mallocator does not work because Mallocator's state is not stored as members of Mallocator, but instead is hidden in the C library implementation.

struct ThreadLocal (
A
) {}

Constructors

this
this()
this(this)
this(this)

ThreadLocal disables all constructors. The intended usage is ThreadLocal!A.instance.

Postblit

Alias This

instance

ThreadLocal!A is a subtype of A so it appears to implement A's allocator primitives.

Members

Static variables

instance
A instance;

The allocator instance.

Examples

import std.experimental.allocator.building_blocks.free_list : FreeList;
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.mallocator : Mallocator;

static assert(!is(ThreadLocal!Mallocator));
static assert(!is(ThreadLocal!GCAllocator));
alias Allocator = ThreadLocal!(FreeList!(GCAllocator, 0, 8));
auto b = Allocator.instance.allocate(5);
static assert(__traits(hasMember, Allocator, "allocate"));

Meta