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

m
malloc(3C) malloc(3C)
_M_SBA_OPTS is used to turn on the small block allocator, and to set up parameters for the small block
allocator, namely, maxfast, grain, and numlblks. Applications with small block allocator turned on usu-
ally run faster than with it turned off. Small block allocator can be turned on through
mallopt(); how-
ever, it is not early enough for C++/Java applications. The environment variable turns it on before the
application starts. The
mallopt() call can still be used the same way. If the environment variable is
set, and no small block allocator has been used, the subsequent
mallopt() calls can still overwrite
whatever is set through
_M_SBA_OPTS. If the environment variable is set, and small block allocator has
been used, then mallopt() will have no effect.
To use this environment variable,
$ 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.
The three new global variables,
__hp_malloc_maxfast
,
__hp_malloc_num_smallblocks
, and
__hp_malloc_grain
, are introduced to over-ride the _M_SBA_OPTS environment option. When
these three variables are initialized within an application,
_M_SBA_OPTS has no effect. This way, a
finely tuned application can lock in performance across different user environments. However, as
_M_ARENA_OPTS, a subsequent call to
mallopt() before any block of memory was allocated will
change the
malloc() behavior. By default, these three variables will be initialized to zero at start up.
It is the same as setting them to
extern int __hp_malloc_maxfast=512;
extern int __hp_malloc_num_smallblocks=100;
extern int __hp_malloc_grain=16;
By default, SBA (Small Block Allocation) is turned on. This may contribute to better application perfor-
mance. A user can set
extern int __hp_malloc_maxfast=-1;
This will turn off SBA.
For all other possible values, please refer to
mallopt().
NOTE: Modifying these variables increases the chances of surfacing existing user memory defects such as
buffer overrun.
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(),orvalloc().
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
mal-
loc():
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
functioning at future releases.
HP-UX 11i Version 2: September 2004 4 Hewlett-Packard Company Section 3615