GC.addRange

Adds p[0 .. sz] to the list of memory ranges to be scanned for pointers during a collection. If p is null, no operation is performed.

Note that p[0 .. sz] is treated as an opaque range of memory assumed to be suitably managed by the caller. In particular, if p points into a GC-managed memory block, addRange does not mark this block as live.

struct GC
extern (C) pragma(mangle, "gc_addRange") static @nogc nothrow pure
void
addRange
(
const void* p
,
size_t sz
,
const TypeInfo ti = null
)

Parameters

p void*

A pointer to a valid memory address or to null.

sz size_t

The size in bytes of the block to add. If sz is zero then the no operation will occur. If p is null then sz must be zero.

ti TypeInfo

TypeInfo to describe the memory. The GC might use this information to improve scanning for pointers or to call finalizers

Examples

// Allocate a piece of memory on the C heap.
enum size = 1_000;
auto rawMemory = core.stdc.stdlib.malloc(size);

// Add it as a GC range.
GC.addRange(rawMemory, size);

// Now, pointers to GC-managed memory stored in
// rawMemory will be recognized on collection.

Meta