/usr/lib/debug/malloc*

Daniel F. Fisher dff at morgan.com
Thu Dec 15 17:44:06 AEST 1988


Mark Lawrence's question about /usr/lib/debug/mallocmap.o prompted me to
do a little experiment.  The following program

------ cut here ------
#include <stdio.h>
extern char *malloc();

main()
{
	char *p, *q;

	mallocmap(); fflush(stdout); write(1, "\n", 1);
	p = malloc(2000); mallocmap(); fflush(stdout); write(1, "\n", 1);
	free(p); mallocmap(); fflush(stdout); write(1, "\n", 1);
	p = malloc(4000); mallocmap(); fflush(stdout); write(1, "\n", 1);
	q = malloc(2000); mallocmap(); fflush(stdout); write(1, "\n", 1);
	free(p); mallocmap(); fflush(stdout); write(1, "\n", 1);
	free(q); mallocmap(); fflush(stdout); write(1, "\n", 1);
}

------ cut here ------

compiled with

	cc -o experiment experiment.c /usr/lib/debug/mallocmap.o

produces the following output when it is run:

------ cut here ------

204f8: 2004 bytes: busy
20ccc: 6188 bytes: free
224f8: 8196 bytes: busy

204f8: 8192 bytes: free
224f8: 8196 bytes: busy

204f8: 4004 bytes: busy
2149c: 4188 bytes: free
224f8: 8196 bytes: busy

204f8: 4004 bytes: busy
2149c: 2004 bytes: busy
21c70: 2184 bytes: free
224f8: 8196 bytes: busy

204f8: 4004 bytes: free
2149c: 2004 bytes: busy
21c70: 2184 bytes: free
224f8: 8196 bytes: busy

204f8: 8192 bytes: free
224f8: 8196 bytes: busy
------ cut here ------

It appears that mallocmap() is a debugging aid that prints a map of free
and busy memory available for use through malloc() and free().

If only I had known this before. . .

But does it take any arguments or return a value?

Daniel Fisher
Morgan Stanley & Co.
dff at morgan.com



More information about the Comp.sys.sun mailing list