home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / next / programm / 5263 < prev    next >
Encoding:
Text File  |  1992-07-27  |  2.1 KB  |  61 lines

  1. Path: sparky!uunet!caen!uflorida!cybernet!news
  2. From: tom@cse.fau.edu (Tom Horton)
  3. Newsgroups: comp.sys.next.programmer
  4. Subject: problem with mstats() under 2.1
  5. Keywords: mstats, malloc, memory usage
  6. Message-ID: <1992Jul27.174618.6477@cybernet.cse.fau.edu>
  7. Date: 27 Jul 92 17:46:18 GMT
  8. Sender: news@cybernet.cse.fau.edu
  9. Organization: Florida Atlantic University, Boca Raton
  10. Lines: 49
  11.  
  12. Hi.  I'm writing some C code that will run on a couple of machines, and I'd  
  13. like to use the mstats() function to get a report on how much mamory has been  
  14. malloc'd.   But it doesn't work like the man page says it should; in fact, it  
  15. doesn't seem to do anything.  It prints nothing and always seems to return 1.
  16.  
  17. The man page says:
  18.      Mstats prints a summary of memory usage by malloc on stderr.
  19.      The efficiency value is calculated based on the rounded-off
  20.      block sizes, and is the ratio of the space available in the
  21.      blocks to the total amount of memory allocated by malloc.
  22.      The value returned is the total amount of memory allocated,
  23.      in bytes.
  24. But this program prints the output that follows:
  25.      #include <stdlib.h>
  26.      #include <stdio.h>
  27.      
  28.      int main (int argc, char *argv[])
  29.      {
  30.        char *buf;
  31.        size_t m_result;
  32.        
  33.        if ( (buf = malloc(30)) == NULL ) {
  34.      fprintf(stderr, "error: malloc failed\n");
  35.      exit(1);
  36.        }
  37.        m_result = mstats();
  38.        printf("mstats returns: %ld\n", (long) m_result);
  39.      
  40.        if ( (buf = malloc(1000)) == NULL ) {
  41.      fprintf(stderr, "error: malloc failed\n");
  42.      exit(1);
  43.        }
  44.        m_result = mstats();
  45.        printf("mstats returns: %ld\n", (long) m_result);
  46.      }
  47.  
  48. OUTPUT:
  49. mstats returns: 1
  50. mstats returns: 1
  51.  
  52. Any suggestions?   I know about MallocDebug, but I'm not really writing a  
  53. NeXTstep application or using IB.
  54. --
  55.  
  56. -------------------------------------------------------------------------
  57. Dr. Thomas B. Horton, Assistant Professor
  58. Dept. of Computer Science and Engineering, Florida Atlantic University
  59. Boca Raton, FL 33431  USA        Phone:  407/367-2674   FAX: 407/367-2800
  60. Internet:  tom@cse.fau.edu       Bitnet: HortonT@fauvax
  61.