Module gfx.core.rc

Reference counting module

Functions

NameDescription
countObj(obj) Counts the number of references of a single object.
disposeAA(arr) Dispose GC allocated associative array of resources
disposeArr(arr) Dispose GC allocated array of resources
disposeObj(obj) Dispose and nullify a single object, that might be null
giveAwayObj(obj) Decreases the reference count of a single object without disposing it. Use this to move an object out of a scope (typically return at the end of a function)
lockObj(obj) Locks a single object.
nullRc() Produces an Rc!T holding a null object
rc(obj) Helper that places an instance of T within a Rc!T
reinitAA(arr) Reinitialises a GC allocated associative array of struct. Useful if the struct release resource in its destructor.
reinitArr(arr) Reinitialises a GC allocated array of struct. Useful if the struct release resource in its destructor.
reinitStruct(t) Reinitialises a single struct Useful if the struct release resource in its destructor.
releaseAA(arr) Release GC allocated associative array of ref-counted resources
releaseArr(arr) Release GC allocated array of ref-counted resources
releaseObj(obj, disposeOnZero) Releases and nullify a single object. The object may be null.
retainAA(arr) Retain GC allocated associative array of ref-counted resources
retainArr(arr) Retain GC allocated array of ref-counted resources
retainObj(obj) Retains a single object.

Interfaces

NameDescription
Disposable A resource that can be disposed
IAtomicRefCounted A atomic reference counted resource. Objects implementing this interface can be safely manipulated as shared. Implementing class should mixin atomicRcCode to use the provided implementation.

Classes

NameDescription
AtomicRefCounted Abstract class that implements IAtomicRefCounted. Should be used over IAtomicRefCounted when practicable to avoid code duplication in the final executable.

Structs

NameDescription
Rc Helper struct that manages the reference count of an object using RAII.
Weak Helper struct that keeps a weak reference to a Resource.

Templates

NameDescription
makeRc Helper that build a new instance of T and returns it within a Rc!T

Manifest constants

NameTypeDescription
atomicRcCode A string that can be mixed-in a class declaration to implement IAtomicRefCounted. dispose is not implemented of course, but is called by release while the object is locked. Classes implementing it are free to do it in a non-thread safe manner as long as dispose does not manipulate external state.
gfxRcMask
isAtomicRefCounted compile time check that T can be ref counted atomically.

Global variables

NameTypeDescription
gfxRcLog immutable(LogTag)