void destroy_Node(Node me) { if (me -> left) { destroy_Node(me -> left); } if (me -> right) { destroy_Node(me -> right); } free(me); }
void destroy_Elimination(Elimination elim){ word w; Iterator iter; if(elim){ destroy_Map(elim->ordering); if(elim->cliques){ iter = get_Iterator(elim->cliques); while(!is_empty(iter)){ w = next_value(iter); destroy_Map((Map) w.v); } destroy_Map(elim->cliques); } if(elim->fill_ins){ if(elim->fill_ins[0]){ free(elim->fill_ins[0]); } free(elim->fill_ins); } if(elim->node_map){ iter = get_Iterator(elim->node_map); while(!is_empty(iter)){ w = next_key(iter); if(w.v){ destroy_Node((Node) w.v); } } destroy_Map(elim->node_map); } free(elim); } }
static void TimeConstruction(int depth) { long tStart, tFinish; int iNumIters = NumIters(depth); Node tempTree; int i; printf("Creating %d trees of depth %d\n", iNumIters, depth); tStart = currentTime(); for (i = 0; i < iNumIters; ++i) { # ifndef GC tempTree = calloc(1, sizeof(Node0)); # else tempTree = GC_NEW(Node0); # endif Populate(depth, tempTree); # ifndef GC destroy_Node(tempTree); # endif tempTree = 0; } tFinish = currentTime(); printf("\tTop down construction took %d msec\n", elapsedTime(tFinish - tStart)); tStart = currentTime(); for (i = 0; i < iNumIters; ++i) { tempTree = MakeTree(depth); # ifndef GC destroy_Node(tempTree); # endif tempTree = 0; } tFinish = currentTime(); printf("\tBottom up construction took %d msec\n", elapsedTime(tFinish - tStart)); }
int main() { Node root; Node longLivedTree; Node tempTree; long tStart, tFinish; long tElapsed; int i, d; double *array; #ifdef GC // GC_full_freq = 30; // GC_free_space_divisor = 16; // GC_enable_incremental(); #endif printf("Garbage Collector Test\n"); printf(" Live storage will peak at %d bytes.\n\n", 2 * sizeof(Node0) * TreeSize(kLongLivedTreeDepth) + sizeof(double) * kArraySize); printf(" Stretching memory with a binary tree of depth %d\n", kStretchTreeDepth); PrintDiagnostics(); # ifdef PROFIL init_profiling(); # endif tStart = currentTime(); // Stretch the memory space quickly tempTree = MakeTree(kStretchTreeDepth); # ifndef GC destroy_Node(tempTree); # endif tempTree = 0; // Create a long lived object printf(" Creating a long-lived binary tree of depth %d\n", kLongLivedTreeDepth); # ifndef GC longLivedTree = calloc(1, sizeof(Node0)); # else longLivedTree = GC_NEW(Node0); # endif Populate(kLongLivedTreeDepth, longLivedTree); ggggc_collectFull(); // Create long-lived array, filling half of it printf(" Creating a long-lived array of %d doubles\n", kArraySize); # ifndef GC array = malloc(kArraySize * sizeof(double)); # else # ifndef NO_PTRFREE array = GC_MALLOC_ATOMIC(sizeof(double) * kArraySize); # else array = GC_MALLOC(sizeof(double) * kArraySize); # endif # endif ggggc_collectFull(); for (i = 0; i < kArraySize/2; ++i) { array[i] = 1.0/i; } PrintDiagnostics(); for (d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2) { TimeConstruction(d); } if (longLivedTree == 0 || array[1000] != 1.0/1000) fprintf(stderr, "Failed\n"); // fake reference to LongLivedTree // and array // to keep them from being optimized away tFinish = currentTime(); tElapsed = elapsedTime(tFinish-tStart); PrintDiagnostics(); printf("Completed in %d msec\n", tElapsed); # ifdef GC printf("Completed %d collections\n", GC_gc_no); printf("Heap size is %d\n", GC_get_heap_size()); # endif # ifdef PROFIL dump_profile(); # endif }