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
demo1.C
#include "HeapStack.H"
class cell : GcObject // This class is a GC class
{
int x;
public:
cell *next; // This field is a pointer to a GC class,
// and must be traversed.
void traverse(); // Because "cell" has internal pointers
// traverse must be defined.
};
void cell::traverse()
{
CmmHeap::heap->scavenge((GcObject **)&next);
// traverse scavenge the internal pointer
// next to reach other cells.
}
main()
{
CmmHeap *MyHeap = new BBStack(100);
// Create the new heap MyHeap.
// Here you can use any of the predefined
// heaps.
cell *t = new cell; // Create a new cell.
// Because you have not specified a heap
// with new, the global variable heap is used.
// heap is initialized to the default heap.
t->next = new (MyHeap) cell; // Create another cell, but in MyHeap
heap = MyHeap;
t->next->next = new cell; // Setting heap to MyHeap, you can allocate cells
// from MyHeap, without specifing it as
// a parameter to new.
heap->collect(); // Collecting on MyHeap
DefaultHeap->collect(); // Collecting on the Default heap.
heap = DefaultHeap; // Reset heap before returning.
}