https://github.com/Unipisa/CMM
Tip revision: 0e186db83a043dcfe9c666dd4c90f9e8d1b9234e authored by Giuseppe Attardi on 27 October 1994, 11:26:20 UTC
1.1 -
1.1 -
Tip revision: 0e186db
demo2.C
#include "HeapStack.H"
struct cell : GcObject {
cell *next;
int value;
cell();
void traverse();
};
void cell::traverse()
{
CmmHeap::heap->scavenge((GcObject **)&next);
}
cell::cell()
{
next = 0;
}
cell root2; // Define a cell variable
main()
{
cell *root1 = new cell; // Define a cell pointer
HeapStack *MyHeap = new HeapStack(10000); // Create a new heap
MyHeap->roots.setp((GcObject **)&root1); // Register the pointer as a root
MyHeap->roots.set(&root2); // Register the cell as a root
root1->next = new(MyHeap) cell; // Allocates some new cells
root2.next = new(MyHeap) cell;
MyHeap->collect(); // The collector will identify
// any allocated cell, starting
// traversing from cell root1 & root2
MyHeap->roots.unsetp((GcObject **)&root1);
// Deregister the local root.
}