The OpenD Programming Language

GC

This struct encapsulates all garbage collection functionality for the D programming language.

struct GC {}

Members

Aliases

BlkInfo
alias BlkInfo = BlkInfo_

Contains aggregate information about a block of managed memory. The purpose of this struct is to support a more efficient query style in instances where detailed information is needed.

Enums

BlkAttr
enum BlkAttr

Elements for a bit field representing memory block attributes. These are manipulated via the getAttr, setAttr, clrAttr functions.

Static functions

addRange
void addRange(void* p, size_t sz, TypeInfo ti)

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.

addRoot
void addRoot(void* p)

Adds an internal root pointing to the GC memory block referenced by p. As a result, the block referenced by p itself and any blocks accessible via it will be considered live until the root is removed again.

addrOf
inout(void)* addrOf(inout(void)* p)
void* addrOf(void* p)

Returns the base address of the memory block containing p. This value is useful to determine whether p is an interior pointer, and the result may be passed to routines such as sizeOf which may otherwise fail. If p references memory not originally allocated by this garbage collector, if p is null, or if the garbage collector does not support this operation, null will be returned.

allocatedInCurrentThread
ulong allocatedInCurrentThread()

Returns the number of bytes allocated for the current thread since program start. It is the same as GC.stats().allocatedInCurrentThread, but faster.

calloc
void* calloc(size_t sz, uint ba, TypeInfo ti, string file, int line, string func)

Requests an aligned block of managed memory from the garbage collector, which is initialized with all bits set to zero. This memory may be deleted at will with a call to free, or it may be discarded and cleaned up automatically during a collection run. If allocation fails, this function will call onOutOfMemory which is expected to throw an OutOfMemoryError.

clrAttr
uint clrAttr(void* p, uint a)

Clears the specified bits for the memory references by p. If p references memory not originally allocated by this garbage collector, points to the interior of a memory block, or if p is null, no action will be performed.

collect
void collect()

Begins a full collection. While the meaning of this may change based on the garbage collector implementation, typical behavior is to scan all stack segments for roots, mark accessible memory blocks as alive, and then to reclaim free space. This action may need to suspend all running threads for at least part of the collection process.

disable
void disable()

Disables automatic garbage collections performed to minimize the process footprint. Collections may continue to occur in instances where the implementation deems necessary for correct program behavior, such as during an out of memory condition. This function is reentrant, but enable must be called once for each call to disable.

enable
void enable()

Enables automatic garbage collection behavior if collections have previously been suspended by a call to disable. This function is reentrant, and must be called once for every call to disable before automatic collections are enabled.

extend
size_t extend(void* p, size_t mx, size_t sz, TypeInfo ti, string file, int line, string func)

Requests that the managed memory block referenced by p be extended in place by at least mx bytes, with a desired extension of sz bytes. If an extension of the required size is not possible or if p references memory not originally allocated by this garbage collector, no action will be taken.

free
void free(void* p)

Deallocates the memory referenced by p. If p is null, no action occurs. If p references memory not originally allocated by this garbage collector, if p points to the interior of a memory block, or if this method is called from a finalizer, no action will be taken. The block will not be finalized regardless of whether the FINALIZE attribute is set. If finalization is desired, call $(REF1 destroy, object) prior to GC.free.

getAttr
uint getAttr(void* p)

Returns a bit field representing all block attributes set for the memory referenced by p. If p references memory not originally allocated by this garbage collector, points to the interior of a memory block, or if p is null, zero will be returned.

inFinalizer
bool inFinalizer()

Queries the GC whether the current thread is running object finalization as part of a GC collection, or an explicit call to runFinalizers.

malloc
void* malloc(size_t sz, uint ba, TypeInfo ti, string file, int line, string func)

Requests an aligned block of managed memory from the garbage collector. This memory may be deleted at will with a call to free, or it may be discarded and cleaned up automatically during a collection run. If allocation fails, this function will call onOutOfMemory which is expected to throw an OutOfMemoryError.

minimize
void minimize()

Indicates that the managed memory space be minimized by returning free physical memory to the operating system. The amount of free memory returned depends on the allocator design and on program behavior.

profileStats
ProfileStats profileStats()

Returns runtime profile stats for currently active GC implementation See core.memory.GC.ProfileStats for list of available metrics.

qalloc
BlkInfo qalloc(size_t sz, uint ba, TypeInfo ti, string file, int line, string func)

Requests an aligned block of managed memory from the garbage collector. This memory may be deleted at will with a call to free, or it may be discarded and cleaned up automatically during a collection run. If allocation fails, this function will call onOutOfMemory which is expected to throw an OutOfMemoryError.

query
BlkInfo query(void* p)

Returns aggregate information about the memory block containing p. If p references memory not originally allocated by this garbage collector, if p is null, or if the garbage collector does not support this operation, BlkInfo.init will be returned. Typically, support for this operation is dependent on support for addrOf.

realloc
void* realloc(void* p, size_t sz, uint ba, TypeInfo ti, string file, int line, string func)

Extend, shrink or allocate a new block of memory keeping the contents of an existing block

removeRange
void removeRange(void* p)

Removes the memory range starting at p from an internal list of ranges to be scanned during a collection. If p is null or does not represent a value previously passed to addRange() then no operation is performed.

removeRoot
void removeRoot(void* p)

Removes the memory block referenced by p from an internal list of roots to be scanned during a collection. If p is null or is not a value previously passed to addRoot() then no operation is performed.

reserve
size_t reserve(size_t sz)

Requests that at least sz bytes of memory be obtained from the operating system and marked as free.

runFinalizers
void runFinalizers(void[] segment)

Runs any finalizer that is located in address range of the given code segment. This is used before unloading shared libraries. All matching objects which have a finalizer in this code segment are assumed to be dead, using them while or after calling this method has undefined behavior.

setAttr
uint setAttr(void* p, uint a)

Sets the specified bits for the memory references by p. If p references memory not originally allocated by this garbage collector, points to the interior of a memory block, or if p is null, no action will be performed.

sizeOf
size_t sizeOf(void* p)

Returns the true size of the memory block referenced by p. This value represents the maximum number of bytes for which a call to realloc may resize the existing block in place. If p references memory not originally allocated by this garbage collector, points to the interior of a memory block, or if p is null, zero will be returned.

stats
Stats stats()

Returns runtime stats for currently active GC implementation See core.memory.GC.Stats for list of available metrics.

Structs

ProfileStats
struct ProfileStats

Aggregation of current profile information

Stats
struct Stats

Aggregation of GC stats to be exposed via public API

Meta