Giggle is a garbage collection library for C++. With Giggle, you don't have to delete or free objects explicitly. With Giggle, you have the choice when you allocate an object of placing its destruction under Giggle's control or controlling it yourself, as if Giggle didn't exist.
Objects collected by Giggle do not need to be from classes that are aware of Giggle, are subclassed from some kind of collectable-by-Giggle class, or are otherwise specially prepared to be garbage-collected. You can place instances of any class under the control of Giggle, even instances of the built-in, non-object ``classes'' such as int. The decision to place an object's destruction under Giggle's control is done on an instance-by-instance basis, not for a whole class.
Giggle uses ``smart pointers'' to do its garbage collection. You write code like this:
#include <iostream> #include <CyberTiggyr/giggle/giggle.hxx> using CyberTiggyr::giggle::HybridCollector; using CyberTiggyr::giggle::Ptr; using CyberTiggyr::giggle::gc; using CyberTiggyr::giggle::setGc; using std::cout; using std::endl; int main () { // // We create the garbage collector we want & tell Giggle about it. // This step is required in all programs. // HybridCollector theCollector; setGc (theCollector); // // Giggle smart pointers to integers. // Ptr<int> g0, g1; // // Plain old pointer to int. Call it a "nude pointer". // int *i = 0; // // Allocate a couple of ints that will be collected by Giggle. // g0 = new (gc ()) int (1); g1 = new (gc ()) int (2); // // Allocate an int that's not collected by Giggle, just to // prove that we still can do it the old fashioned way even // when we're using Giggle. // i = new int (3); // // We can use smart pointers just like nude pointers. // cout << *g0 << ", " << *g1 << ", " << *i << endl; // // We gotta delete i because it's not garbage-collected, but we // don't delete g0 or g1. Giggle will delete the objects they // point to. (That's the point of using Giggle.) // delete i; // // Returning from 'main' will destroy g0, g1, and theCollector. // When theCollector is destroyed, it will destroy the integers // we allocated inside it. (Those are the integers that g0 and // g1 pointed to.) // return 0; }
Giggle allows the programmer to select the garbage collection algorithm at run-time. Giggle ships with a reference counting garbage collector & a garbage collector that is actually an interface to the Boehm collector. Also, programmrs may define their own garbage collectors & plug them into Giggle.