mallocng.3x (2012 03)
m
mallocng(3X)
Itanium(R)-based Systems Only
mallocng(3X)
NAME
mallocng, libmallocng - library with an alternate memory allocator
DESCRIPTION
The
libmallocng library provides a memory allocator called
mallocng which can be used as an
alternative to the memory allocator in the
libc system library.
The
libmallocng library is available on Itanium-based systems only.
The APIs provided in this library are
malloc
, calloc, realloc, free, valloc, mallopt, and
mallinfo. These APIs are documented in the malloc (3C) manpage.
In order to use the
mallocng memory allocator, applications need to link with the
libmallocng
library, making sure that the libmallocng library is placed before the system C library on the com-
piler line or link line.
For example:
cc alloc_test.c -lmallocng
or
cc alloc_test.c -lmallocng -lc
The memory allocator provided in the libmallocng library uses a different set of algorithms when
compared to the default memory allocator in libc. Applications that link with the libmallocng
library may see improved performance for small blocks or if the application is multi-threaded. Blocks of
size less than 1024 bytes may be considered small.
The memory overhead of the
mallocng allocator may be less or more than the default allocator, depend-
ing on the application behavior. Specifically, for multi-threaded applications that create a large number
of threads, this allocator is likely to occupy more memory than the default allocator.
Using the
mallocng allocator may expose existing memory defects in the application. Common memory
defects include buffer overrun, attempting to free the same block twice, using memory after it is freed,
and attempting to free an invalid pointer.
Users are advised to benchmark their applications with the default memory allocator in
libc and with
the mallocng allocator in libmallocng before using the mallocng allocator in a production
environment.
Differences From the Default Memory Allocator
The
M_MXFAST, M_NLBLKS, M_GRAIN, and M_REL_LAST_FBLK
values to the cmd argument of mal-
lopt() does not have any effect on the mallocng allocator.
After a call to the
mallinfo() API, the hblks , hblkhd , and keepcost fields of the
mallinfo structure
have no special meaning. For multi-threaded applications, the value returned in the
mallinfo struc-
ture by
mallinfo() is undefined.
The environment variables
_M_ARENA_OPTS, _M_SBA_OPTS, and _M_CACHE_OPTS have no influence
on the
mallocng allocator.
The global variables
__hp_malloc_maxfast, __hp_malloc_num_smallblocks
, and
__hp_malloc_grain have no influence on the mallocng allocator.
EXTERNAL INFLUENCES
_MALLOCNG_LBC_OPTS
The environment variable
_MALLOCNG_LBC_OPTS can be used to provide a hint to the mallocng allo-
cator to return large blocks to the system. The
mallocng allocator uses sum of the values mentioned in
_MALLOCNG_LBC_OPTS as the hint.
Here is an example of how to use
_MALLOCNG_LBC_OPTS:
$ export _MALLOCNG_LBC_OPTS=128:256
If the tunable is set as above, then the mallocng allocator will determine if it is best to return large
blocks to the system once the process allocates greater than 384 MB of memory.
By default, the above environment variable is set to
_MALLOCNG_LBC_OPTS=512:1024.
Using the environment variable as
_MALLOCNG_LBC_OPTS=100:200 is same as using
_MALLOCNG_LBC_OPTS=50:250.
HP-UX 11i Version 3: March 2012 − 1 − Hewlett-Packard Company 1