HP-UX Reference (11i v1 05/09) - 3 Library Functions A-M (vol 6)
m
malloc(3C) malloc(3C)
$ export _M_SBA_OPTS = 512:100:16
This means that the maxfast size is 512, the number of small blocks is 100, and the grain size is 16. You
have to supply all 3 values, and in that order. If not, the default values will be used instead.
_M_ARENA_OPTS
has no effects on non-threaded applications, while
_M_SBA_OPTS has.
WARNINGS
malloc() functions use brk() and sbrk() (see brk(2)) to increase the address space of a process.
Therefore, an application program that uses
brk() or
sbrk() must not use them to decrease the address
space, because this confuses the
malloc() functions.
free() and realloc() do not check their pointer argument for validity.
The following actions are considered bad programming practices and should not be done. The results are
unpredictable, probably undesirable and not supported. Examples of undesirable results are loss of data,
memory fault, bus error or infinite loop.
• Attempting to free() or realloc() a pointer not generated as the result of a call to
mal-
loc()
, realloc() , calloc(),or
valloc().
• Reading or writing data outside the boundaries of an allocated block.
• Attempting to
realloc() an aligned block such as the result of valloc().
The following actions are strongly discouraged and may be unsupported in a future version of malloc():
• Attempting to
free() the same block twice.
• Depending on unmodified contents of a block after it has been freed.
• Attempting to realloc() a block after it is freed.
Undocumented features of earlier memory allocators have not been duplicated. Applications which used
any of the above bad programming practices or discouraged practices are not guaranteed to continue func-
tioning at future releases.
Obsolescent Interfaces
The memorymap(3C) function has been deprecated as of HP-UX 11.11, and will be obsolete at the next
release of HP-UX. The mallinfo() function is more useful for malloc statistics.
COMPATIBILITY
The only external difference between the old malloc(3X) allocator and the malloc(3C) allocator is that the
old allocator would return a NULL pointer for a request of zero bytes. The malloc(3C) allocator returns a
valid memory address. This is not a concern for most applications.
SEE ALSO
brk(2), errno(2), thread_safety(5).
STANDARDS CONFORMANCE
malloc(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
calloc(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
free(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
mallinfo() : SVID2, XPG2
mallopt(): SVID2, SVID3, XPG2
realloc(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
HP-UX 11i Version 1: September 2005 − 4 − Hewlett-Packard Company Section 3−−545