home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / Mem_PrintConfig.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-22  |  2.9 KB  |  106 lines

  1. /* 
  2.  * Mem_PrintConfig.c --
  3.  *
  4.  *    Source code for the "Mem_PrintConfig" library procedure.  See memInt.h
  5.  *    for overall information about how the allocator works..
  6.  *
  7.  * Copyright 1988 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/Mem_PrintConfig.c,v 1.2 89/01/30 15:39:35 brent Exp $ SPRITE (Berkeley)";
  19. #endif not lint
  20.  
  21. #include "memInt.h"
  22.  
  23. /*
  24.  * ----------------------------------------------------------------------------
  25.  *
  26.  * Mem_PrintConfig --
  27.  *
  28.  *    Prints out the exact configuration of the dynamic memory allocator
  29.  *    using the default printing routine.
  30.  *
  31.  * Results:
  32.  *      None.
  33.  *
  34.  * Side effects:
  35.  *      Stuff gets printed.
  36.  *
  37.  * ----------------------------------------------------------------------------
  38.  */
  39.  
  40. ENTRY void
  41. Mem_PrintConfig()
  42. {
  43.     register Address ptr;
  44.     int i, j;
  45.  
  46.     LOCK_MONITOR;
  47.  
  48.     if (!memInitialized) {
  49.     (*memPrintProc)(memPrintData, "Allocator not initialized yet.\n");
  50.     return;
  51.     }
  52.  
  53. #define VERBOSE 2
  54. #ifdef VERBOSE
  55.     (*memPrintProc)(memPrintData, "Small object allocator:\n");
  56.     for (i = 2; i < BIN_BUCKETS; i++) {
  57.     if ((memFreeLists[i] == (Address) NULL)
  58.         || (memFreeLists[i] == NOBIN)) {
  59.         continue;
  60.     }
  61.     (*memPrintProc)(memPrintData, "    %d bytes:", INDEX_TO_BLOCKSIZE(i));
  62.     j = 5;
  63.     for (ptr = memFreeLists[i]; ptr != (Address) NULL; 
  64.         ptr = (Address) GET_ADMIN(ptr)) {
  65.         if (j == 5) {
  66.         (*memPrintProc)(memPrintData, "\n    ");
  67.         j = 0;
  68.         } else {
  69.         j += 1;
  70.         }
  71.         (*memPrintProc)(memPrintData, "%12#x", ptr);
  72.     }
  73.     (*memPrintProc)(memPrintData, "\n");
  74.     }
  75. #endif VERBOSE
  76.  
  77.     (*memPrintProc)(memPrintData, "Large object allocator:\n");
  78.  
  79. #ifdef MEM_TRACE
  80.     (*memPrintProc)(memPrintData, "    Location   Orig. Size   State\n");
  81. #else
  82.     (*memPrintProc)(memPrintData, "    Location       Size     State\n");
  83. #endif MEM_TRACE
  84.  
  85.     for (ptr = memFirst; ptr != memLast; ptr += SIZE(GET_ADMIN(ptr))) {
  86.  
  87. #ifdef MEM_TRACE
  88.     (*memPrintProc)(memPrintData, "%12#x %10d", ptr, GET_ORIG_SIZE(ptr));
  89.     if (IS_DUMMY(GET_ADMIN(ptr))) {
  90.         (*memPrintProc)(memPrintData, "     Dummy\n");
  91.     } else if (IS_IN_USE(GET_ADMIN(ptr))) {
  92.         (*memPrintProc)(memPrintData, "     In use (PC=0x%x)\n", GET_PC(ptr));
  93. #else
  94.     (*memPrintProc)(memPrintData, "%12#x %10d", ptr, SIZE(GET_ADMIN(ptr)));
  95.     if (IS_DUMMY(GET_ADMIN(ptr))) {
  96.         (*memPrintProc)(memPrintData, "     Dummy\n");
  97.     } else if (IS_IN_USE(GET_ADMIN(ptr))) {
  98.         (*memPrintProc)(memPrintData, "     In use\n");
  99. #endif MEM_TRACE
  100.     } else {
  101.         (*memPrintProc)(memPrintData, "     Free\n");
  102.     }
  103.     }
  104.     UNLOCK_MONITOR;
  105. }
  106.