HP-UX Reference (11i v2 04/09) - 3 Library Functions A-M (vol 6)

m
malloc(3C) malloc(3C)
standard output. If the value of the show_stats parameter is 1, statistics concerning
number of blocks and sizes used will also be written. If the value is zero, only the
memory map will be written.
The addresses and sizes displayed by
memorymap() may not correspond to those
requested by an application. The size of a block (as viewed by the allocator)
includes header information and padding to properly align the block. The address
is also offset by a certain amount to accommodate the header information.
memorymap() has been deprecated at HP-UX 11i Version 1 and is now obsolete.
alloca() Allocates space from the stack of the caller for a block of at least size bytes, but does
not initialize the space. The space is automatically freed when the calling routine
exits.
Memory returned by
alloca() is not related to memory allocated by other
memory allocation functions. Behavior of addresses returned by
alloca() as
parameters to other memory functions is undefined.
The implementation of this routine is system dependent and its use is discouraged.
RETURN VALUE
Upon successful completion,
malloc(), realloc(), calloc(), and valloc() return a pointer to
space suitably aligned (after possible pointer coercion) for storage of any type of object. Otherwise, they
return a NULL pointer. If realloc() returns a NULL pointer, the memory pointed to by the original
pointer is left intact.
mallopt() returns zero for success and nonzero for failure.
DIAGNOSTICS
malloc(), realloc(), calloc(), and valloc() return a NULL pointer if there is no available
memory, or if the memory managed by malloc() has been detectably corrupted. This memory may
become corrupted if data is stored outside the bounds of a block, or if an invalid pointer (a pointer not
generated by malloc(), realloc(), calloc(),orvalloc() is passed as an argument to
free()
or realloc().
If
mallopt() is called after any allocation of a small block and cmd is not set to
M_BLOCK or
M_UBLOCK,orifcmd or value is invalid, nonzero is returned. Otherwise, it returns zero.
ERRORS
[ENOMEM]
malloc(), realloc(), calloc(), and valloc() set errno to [ENOMEM] and
return a NULL pointer when an out-of-memory condition arises.
[EINVAL]
malloc(), realloc(), calloc(), and valloc()
set errno to [EINVAL] and
return a NULL pointer when the memory being managed by
malloc() has been detect-
ably corrupted.
EXTERNAL INFLUENCES
The performance of the
malloc() family can be tuned via two environment variables,
_M_ARENA_OPTS and _M_SBA_OPTS, and three new global variables, __hp_malloc_maxfast
,
__hp_malloc_num_smallblocks and __hp_malloc_grain
.
For threaded applications,
malloc() uses multiple arenas. Memory requests from different threads are
handled by different arenas. _M_ARENA_OPTS can be used to adjust the number of arenas and how
many pages each time an arena expands itself (the expansion factor), assuming that the page size is 4096
bytes. In general, the more threads in an application, the more arenas should be used for better perfor-
mance. The number of arenas can be from 1 to 64 for threaded applications. For non-threaded applica-
tions, only one arena is used. If the environment variable is not set, or the number of arenas is set to be
out of the range, the default number of 8 will be used. The expansion factor is from 1 to 4096, default
value is 32. Again, if the factor is out of the range, the default value will be used.
Here is an example of how to use
_M_ARENA_OPTS,
$ export _M_ARENA_OPTS = 16:8
This means that the number of arenas is 16, and the expansion size is 8*4096 bytes. In general, the more
arenas you use, the smaller the expansion factor should be, and vice versa.
Section 3614 Hewlett-Packard Company 3 HP-UX 11i Version 2: September 2004