View source code Display the source code in core/memory.d from which this page was generated on github. 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. Page wiki View or edit the community-maintained wiki page associated with this page.

Function core.memory.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.

Prototype

static void addRange(
  const(void*) p,
  ulong sz,
  const(TypeInfo) ti = null
) nothrow @nogc;

Parameters

NameDescription
p A pointer to a valid memory address or to null.
sz 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 to describe the memory. The GC might use this information to improve scanning for pointers or to call finalizers

Example

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

Authors

Sean Kelly, Alex Rønne Petersen

License

Boost License 1.0

Comments