https://github.com/Unipisa/CMM
Tip revision: 29c7c5881c0ff2ef9e3a96be37e6eaef9b33a201 authored by Giuseppe Attardi on 07 November 1994, 16:36:34 UTC
1.3 -
1.3 -
Tip revision: 29c7c58
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.
}