Esempio n. 1
0
static void cleanup_exit(int exit_code)
{
	verbose("%s: exit with code %d\n", PROGNAME, exit_code);
	free_i18n_strings();
	mh_dump_used(stdout);
	mh_dump(stdout);
	mh_diagnostic(stdout);
	exit(exit_code);
}
Esempio n. 2
0
int main()
{
  HeapType *heap;
  void  *ptr1, *ptr2, *ptr3, *ptr4;

  heap = (HeapType *) malloc(sizeof(HeapType));
  mh_init(heap);

  ptr1 = mh_alloc(heap, 5*sizeof(int), "ints");
  ptr2 = mh_alloc(heap, 10*sizeof(double), "doubles");
  ptr3 = mh_alloc(heap, 8*sizeof(char), "chars");
  ptr4 = mh_alloc(heap, 12*sizeof(StudentType), "Students");

  printf("\nDUMP 1, byte count = %d\n", mh_count(heap));
  mh_dump(heap);

  mh_dealloc(heap, ptr1);
  mh_dealloc(heap, ptr2);
  mh_dealloc(heap, ptr3);

  printf("\nDUMP 2, byte count = %d\n", mh_count(heap));
  mh_dump(heap);

  mh_collect(heap);

  printf("\nDUMP 3, byte count = %d\n", mh_count(heap));
  mh_dump(heap);


  /* Additional tests:
   *    70  floats
   *     9  MatrixTypes
   *    20  ServerEntryTypes
   *  32+2  Point3DTypes
   *    10  longs
   *    64  HeapTypes (lol)
   **/
  printf("\n--> ADDITIONAL TESTING:\n");

  mh_alloc(heap, 70*sizeof(float), "floats");

  printf("\nDUMP 4, byte count = %d\n", mh_count(heap));
  mh_dump(heap);

  void *server_entries;
  server_entries = mh_alloc(heap, 20*sizeof(ServerEntryType), "ServerEntries");
  mh_alloc(heap, 9*sizeof(MatrixType), "Matrices");

  printf("\nDUMP 5, byte count = %d\n", mh_count(heap));
  mh_dump(heap);

  mh_dealloc(heap, server_entries);
  mh_alloc(heap, 32*sizeof(Point3DType), "3D points");
  mh_alloc(heap, 2*sizeof(Point3DType), "3D Points");

  printf("\nDUMP 6, byte count = %d\n", mh_count(heap));
  mh_dump(heap);

  mh_collect(heap);
  mh_alloc(heap, 10*sizeof(long), "longs");

  printf("\nDUMP 7, byte count = %d\n", mh_count(heap));
  mh_dump(heap);

  mh_alloc(heap, 64*sizeof(HeapType), "heaps"); // not initialized

  printf("\nDUMP 8, byte count = %d\n", mh_count(heap));
  mh_dump(heap);

  printf("\n\n");
  mh_cleanup(heap);
  free(heap);

  return 0;
}