.\" the source, must acknowledge the copyright and authors of this work.
.\" %%%LICENSE_END
.\"
-.TH MALLOC_INFO 3 2013-04-19 "GNU" "Linux Programmer's Manual"
+.TH MALLOC_INFO 3 2019-03-06 "GNU" "Linux Programmer's Manual"
.SH NAME
malloc_info \- export malloc state to a stream
.SH SYNOPSIS
.nf
.B #include <malloc.h>
-.sp
-.BI "int malloc_info(int " options ", FILE *" fp );
+.PP
+.BI "int malloc_info(int " options ", FILE *" stream );
.fi
.SH DESCRIPTION
The
of the memory-allocation
implementation in the caller.
The string is printed on the file stream
-.IR fp .
+.IR stream .
The exported string includes information about all arenas (see
.BR malloc (3)).
-
+.PP
As currently implemented,
.I options
must be zero.
.SH VERSIONS
.BR malloc_info ()
was added to glibc in version 2.10.
+.SH ATTRIBUTES
+For an explanation of the terms used in this section, see
+.BR attributes (7).
+.TS
+allbox;
+lb lb lb
+l l l.
+Interface Attribute Value
+T{
+.BR malloc_info ()
+T} Thread safety MT-Safe
+.TE
+.sp 1
.SH CONFORMING TO
This function is a GNU extension.
.SH NOTES
because the information may change over time
(according to changes in the underlying implementation).
The output XML string includes a version field.
-
+.PP
The
.BR open_memstream (3)
function can be used to send the output of
.BR malloc_info ()
directly into a buffer in memory, rather than to a file.
-
+.PP
The
.BR malloc_info ()
function is designed to address deficiencies in
The main thread creates blocks of this size,
the second thread created by the program allocates blocks of twice this size,
the third thread allocates blocks of three times this size, and so on.
-
+.PP
The program calls
.BR malloc_info ()
twice to display the memory-allocation state.
The first call takes place before any threads
are created or memory allocated.
The second call is performed after all threads have allocated memory.
-
+.PP
In the following example,
the command-line arguments specify the creation of one additional thread,
and both the main thread and the additional thread
After the blocks of memory have been allocated,
.BR malloc_info ()
shows the state of two allocation arenas.
+.PP
.in +4
-.nf
-
+.EX
.RB "$ " "getconf GNU_LIBC_VERSION"
glibc 2.13
.RB "$ " "./a.out 1 10000 100"
<aspace type="total" size="2113536"/>
<aspace type="mprotect" size="2113536"/>
</malloc>
-.fi
+.EE
.in
.SS Program source
-.nf
-
+.EX
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
static size_t blockSize;
static int numThreads, numBlocks;
-#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \\
+#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
} while (0)
static void *
if (argc < 4) {
fprintf(stderr,
- "%s num\-threads num\-blocks block\-size [sleep\-time]\\n",
+ "%s num\-threads num\-blocks block\-size [sleep\-time]\en",
argv[0]);
exit(EXIT_FAILURE);
}
if (thr == NULL)
errExit("calloc");
- printf("============ Before allocating blocks ============\\n");
+ printf("============ Before allocating blocks ============\en");
malloc_info(0, stdout);
/* Create threads that allocate different amounts of memory */
sleep(2); /* Give all threads a chance to
complete allocations */
- printf("\\n============ After allocating blocks ============\\n");
+ printf("\en============ After allocating blocks ============\en");
malloc_info(0, stdout);
exit(EXIT_SUCCESS);
}
-.fi
+.EE
.SH SEE ALSO
.BR mallinfo (3),
.BR malloc (3),