mirror of https://github.com/mkerrisk/man-pages
mallinfo.3: Update example program to use mallinfo2()
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
parent
5bf7268349
commit
e9e534537d
|
@ -197,7 +197,7 @@ However, because some internal bookkeeping values may be of type
|
|||
the reported values may wrap around zero and thus be inaccurate.
|
||||
.SH EXAMPLES
|
||||
The program below employs
|
||||
.BR mallinfo ()
|
||||
.BR mallinfo2 ()
|
||||
to retrieve memory allocation statistics before and after
|
||||
allocating and freeing some blocks of memory.
|
||||
The statistics are displayed on standard output.
|
||||
|
@ -272,22 +272,22 @@ Topmost releasable block (keepcost): 31168
|
|||
#include <string.h>
|
||||
|
||||
static void
|
||||
display_mallinfo(void)
|
||||
display_mallinfo2(void)
|
||||
{
|
||||
struct mallinfo mi;
|
||||
struct mallinfo2 mi;
|
||||
|
||||
mi = mallinfo();
|
||||
mi = mallinfo2();
|
||||
|
||||
printf("Total non\-mmapped bytes (arena): %d\en", mi.arena);
|
||||
printf("# of free chunks (ordblks): %d\en", mi.ordblks);
|
||||
printf("# of free fastbin blocks (smblks): %d\en", mi.smblks);
|
||||
printf("# of mapped regions (hblks): %d\en", mi.hblks);
|
||||
printf("Bytes in mapped regions (hblkhd): %d\en", mi.hblkhd);
|
||||
printf("Max. total allocated space (usmblks): %d\en", mi.usmblks);
|
||||
printf("Free bytes held in fastbins (fsmblks): %d\en", mi.fsmblks);
|
||||
printf("Total allocated space (uordblks): %d\en", mi.uordblks);
|
||||
printf("Total free space (fordblks): %d\en", mi.fordblks);
|
||||
printf("Topmost releasable block (keepcost): %d\en", mi.keepcost);
|
||||
printf("Total non\-mmapped bytes (arena): %zu\en", mi.arena);
|
||||
printf("# of free chunks (ordblks): %zu\en", mi.ordblks);
|
||||
printf("# of free fastbin blocks (smblks): %zu\en", mi.smblks);
|
||||
printf("# of mapped regions (hblks): %zu\en", mi.hblks);
|
||||
printf("Bytes in mapped regions (hblkhd): %zu\en", mi.hblkhd);
|
||||
printf("Max. total allocated space (usmblks): %zu\en", mi.usmblks);
|
||||
printf("Free bytes held in fastbins (fsmblks): %zu\en", mi.fsmblks);
|
||||
printf("Total allocated space (uordblks): %zu\en", mi.uordblks);
|
||||
printf("Total free space (fordblks): %zu\en", mi.fordblks);
|
||||
printf("Topmost releasable block (keepcost): %zu\en", mi.keepcost);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -311,7 +311,7 @@ main(int argc, char *argv[])
|
|||
freeEnd = (argc > 5) ? atoi(argv[5]) : numBlocks;
|
||||
|
||||
printf("============== Before allocating blocks ==============\en");
|
||||
display_mallinfo();
|
||||
display_mallinfo2();
|
||||
|
||||
for (int j = 0; j < numBlocks; j++) {
|
||||
if (numBlocks >= MAX_ALLOCS) {
|
||||
|
@ -327,13 +327,13 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
printf("\en============== After allocating blocks ==============\en");
|
||||
display_mallinfo();
|
||||
display_mallinfo2();
|
||||
|
||||
for (int j = freeBegin; j < freeEnd; j += freeStep)
|
||||
free(alloc[j]);
|
||||
|
||||
printf("\en============== After freeing blocks ==============\en");
|
||||
display_mallinfo();
|
||||
display_mallinfo2();
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue