🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #260

problem with mstats() under 2.1

#260
From: Tom Horton
Date: Mon, 27 Jul 1992 17:46
49 lines
2197 bytes
Hi.  I'm writing some C code that will run on a couple of machines, and I'd  
like to use the mstats() function to get a report on how much mamory has been  
malloc'd.   But it doesn't work like the man page says it should; in fact, it  
doesn't seem to do anything.  It prints nothing and always seems to return 1.

The man page says:
     Mstats prints a summary of memory usage by malloc on stderr.
     The efficiency value is calculated based on the rounded-off
     block sizes, and is the ratio of the space available in the
     blocks to the total amount of memory allocated by malloc.
     The value returned is the total amount of memory allocated,
     in bytes.
But this program prints the output that follows:
     #include <stdlib.h>
     #include <stdio.h>
     
     int main (int argc, char *argv[])
     {
       char *buf;
       size_t m_result;
       
       if ( (buf = malloc(30)) == NULL ) {
	 fprintf(stderr, "error: malloc failed\n");
	 exit(1);
       }
       m_result = mstats();
       printf("mstats returns: %ld\n", (long) m_result);
     
       if ( (buf = malloc(1000)) == NULL ) {
	 fprintf(stderr, "error: malloc failed\n");
	 exit(1);
       }
       m_result = mstats();
       printf("mstats returns: %ld\n", (long) m_result);
     }

OUTPUT:
mstats returns: 1
mstats returns: 1

Any suggestions?   I know about MallocDebug, but I'm not really writing a  
NeXTstep application or using IB.
--

-------------------------------------------------------------------------
Dr. Thomas B. Horton, Assistant Professor
Dept. of Computer Science and Engineering, Florida Atlantic University
Boca Raton, FL 33431  USA        Phone:  407/367-2674   FAX: 407/367-2800
Internet:  tom@cse.fau.edu       Bitnet: HortonT@fauvax
Technical Details
Message-ID: <1992Jul27.174618.6477@cybernet.cse.fau.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!caen!uflorida!cybernet!news

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!caen!uflorida!cybernet!news
From: tom@cse.fau.edu (Tom Horton)
Newsgroups: comp.sys.next.programmer
Subject: problem with mstats() under 2.1
Keywords: mstats, malloc, memory usage
Message-ID: <1992Jul27.174618.6477@cybernet.cse.fau.edu>
Date: 27 Jul 92 17:46:18 GMT
Sender: news@cybernet.cse.fau.edu
Organization: Florida Atlantic University, Boca Raton
Lines: 49