RTGC Tutorial
The basic concepts are:
- Include librtgc/Rtgc.h
- All classes derive from RTGC::Void
- All pointers are stored in a DREF or an IREF when they are
created.
- Any pointer that is stored on the stack (an automatics
variable or a function argument) is placed in a DREF
- Any pointer that is stored on the heap (as a field in a
class) is placed in an IREF
- Once a pointer has been stored in a DREF or an IREF, it may
be stored in a WREF. A WREF allows access to the pointer as
long as it has not been orphaned. A WREF will not prevent a
pointer from being orphaned and freed.
- Use the macro RTGC_DEFINE_REFS(className) to create
types classNameD, classNameI, and classNameW representing typed
DREFs, IREFs, and WREFs for the class
Here's a short example that shows about everything.
#include <librtgc/Rtgc.h>
RTGC_DEFINE_REFS(ClassName)
class ClassName : public RTGC::Void
{
public:
ClassName(ClassNameD child);
ClassNameI child;
ClassNameW weak;
};
ClassName::ClassName(ClassNameD _child)
: child(this, _child)
{
}
main(int argc, char **argv)
{
RTGC::initialize(argc, argv);
ClassNameD a = new ClassName(0);
ClassNameD b = new ClassName(a);
b->child = a;
b->weak = a;
a = 0;
b = 0;
}
Stephen L. Favor
Last modified: Wed Dec 24 20:29:39 CST 2003