March 2024 | ||||||
Mo | Tu | We | Th | Fr | Sa | Su |
26 | 27 | 28 | 29 | 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
1 | 2 | 3 | 4 | 5 | 6 | 7 |
int mallopt (int param, int value);
int malloc_trim (size_t pad);
size_t malloc_usable_size (void *ptr);
void malloc_stats (void);
void *malloc_get_state (void);
int malloc_set_state (void *ptr);
struct mallinfo mallinfo (void);
mallopt() allows tuning of the parameters affecting allocation. param is one of the constants listed below; value should be specified in bytes.
Note that not all unused memory is able to be returned to the OS; in particular, it is not possible to return an unused block when an in-use block lies between it and the ``top'' of the data segment. However, the free block may be used to satisfy future allocation requests.
Smaller values for this parameter cause sbrk() to be called more frequently with a negative argument, reducing memory usage, but with increased overhead of extra syscalls. A value of -1 disables trimming. Default: 128*1024.
If set to 0, errors are silently ignored (but the behavior of the program is undefined).
If the low bit is set, an error message is printed; If the third-lowest bit is unset, the message is surrounded by asterisks ("*") and includes the relevant pointer address.
If the second-lowest bit is set, the program is then terminated with abort().
The default value for glibc 2.3.3 and earlier was 1, causing only an informative message to be output. glibc-2.3.4 changes the default to 3, which also causes the program to abort.
malloc_trim() explicitly requests that any unused memory space be returned to the OS. Note that this happens automatically when free() is called with a sufficiently large chunk; see the M_TRIM_THRESHOLD and M_TOP_PAD parameters, above. pad specifies the number of bytes to be retained for use in future allocation requests; when called by free(), this is the value of M_TOP_PAD.
malloc_usable_size() returns the number of bytes available in the dynamically allocated buffer ptr, which may be greater than the requested size (but is guaranteed to be at least as large, if the request was successful). Typically, you should store the requested allocation size rather than use this function.
malloc_stats() outputs to stderr some information about the program's usage of dynamic memory. Information for each arena is displayed.
in use bytes is the amount of that space which the program has requested and are in use.
max mmap regions is largest number of mmap() regions allocated at a given time.
max mmap bytes is the largest total amount of address space ever allocated by mmap() at a given time.
system bytes and in use bytes output appears twice, once excluding mmap, and later including mmap().
malloc_get_state() returns a ... malloc_set_state()
mallinfo() returns a struct mallinfo with allocation information, similar to what is printed by malloc_stats(). The return value is a structure, not a pointer; it is thread-safe. Only the information for the main arena is returned. The structure contains the following members:
malloc_trim() returns 1 if any memory was returned to the OS, and 0 otherwise.
malloc_usable_size() returns the usable size of the allocated region beginning at ptr, or 0 if ptr is NULL.
malloc_get_state() returns a pointer to a description of the state of the allocation routines, or NULL on error.
malloc_set_state() returns 0 on success, and nonzero on error.
mallinfo() returns a structure containing information about the dynamic memory use of the program.
The default values listed for the mallopt() parameters may vary between installations, and should only serve as a guideline while tweaking the values; refer to the source code for your distribution's glibc package to establish the real defaults.
Only the first byte of MALLOC_CHECK_ is considered; "10" is interpreted as 1, and "64" is interpreted as 6.
That standard also defines the mallopt() parameters M_NLBLKS, M_GRAIN, and M_KEEP, but these values have no effect in the glibc implementation.
The remainder of these functions and variables are GNU extensions, and should not be used in programs intended to be portable.