home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Kernel / EmMalloc / stats.c < prev   
Encoding:
C/C++ Source or Header  |  1990-08-17  |  1.1 KB  |  62 lines

  1. #include <stdio.h>
  2.  
  3. #ifndef NOMALLOCCHECK
  4. #define MAXBLOCKS 10000
  5. typedef struct {
  6.     unsigned int     callerspc;
  7.     unsigned int      num;
  8.     unsigned int     mp;
  9. } block, *bp;
  10. extern block ht[MAXBLOCKS];
  11. #endif
  12. #define Hash(N) (((N) >> 3) % MAXBLOCKS)
  13.  
  14. #define panicabort(S) { printf( "%s\n", S); abort(); }
  15. #define MAGIC  0x99773311
  16. #define MAGIC2 0x11773399
  17.  
  18. extern unsigned int totalAllocated, totalFreed;
  19.  
  20. malloc_stats()
  21. {
  22.     printf( "total allocations %d\ntotal frees %d\n",
  23.     totalAllocated, totalFreed);
  24. }
  25.  
  26. /*ARGSUSED*/
  27. malloc_doall(f)
  28. int (*f)();
  29. {
  30. #ifndef NOMALLOCCHECK
  31.     register bp p;
  32.     for (p = ht; p < &ht[MAXBLOCKS]; p++)
  33.     if (p->mp != 0) (*f)(p->callerspc, p->num, p->mp);
  34. #endif
  35. }
  36.  
  37. checkitout(callerspc, num, p)
  38. int callerspc, num;
  39. register char *p;
  40. {
  41.   if (*(int *)(p-4) != MAGIC || *(int *)(p+num) != MAGIC2) {
  42.     printf( "corrupted block 0x%x allocated from 0x%x\n",
  43.       p, callerspc);
  44.   }
  45. }
  46.  
  47. malloc_check()
  48. {
  49.   malloc_doall(checkitout);
  50. }
  51.  
  52. displayHunk(pc, num, mp)
  53. unsigned int pc, num, mp;
  54. {
  55.   printf( "Allocated from 0x%x, size %d, addr 0x%x\n", pc, num, mp);
  56. }
  57.  
  58. malloc_display()
  59. {
  60.   malloc_doall(displayHunk);
  61. }
  62.