From e9e534537db6f0ea6cefc7f84a1338a8c7bc9e18 Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Sat, 17 Oct 2020 19:04:58 +0200 Subject: [PATCH] mallinfo.3: Update example program to use mallinfo2() Signed-off-by: Michael Kerrisk --- man3/mallinfo.3 | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/man3/mallinfo.3 b/man3/mallinfo.3 index 40e07ebc4..c5c6e9de0 100644 --- a/man3/mallinfo.3 +++ b/man3/mallinfo.3 @@ -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 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); }