// allocer.cc // prototypical program doing memory allocation #include "myhooks.h" // as if automatically inserted at top of file #include "inst.h" // instrumentation routines #include // printf #include // malloc, free class Pair { public: Pair *car; Pair *cdr; public: Pair(Pair *a, Pair *d) : car(a), cdr(d) {} }; Pair *graph = NULL; void foo(...); // for pretending that something is used int main() { // from the stack, a tree structure Pair *top = new Pair( new Pair( new Pair(NULL,NULL), NULL), new Pair(NULL,NULL)); // from the static data, a graph Pair *temp = new Pair(NULL, NULL); graph = new Pair( new Pair(temp, NULL), temp); temp = NULL; // hide my tracks // from stack to array-allocated char *buf = new char[80]; // invoke the analyzer if we are compiled with malloc redefined #ifdef malloc memoryGraphAnalysis(); #endif // pretend they're all used foo(top, graph, buf); // verify delete[] works delete[] buf; return 0; } void foo(...) {}