C/C++ Programmer's Guide (G06.25+)

Compiler Pragmas
HP C/C++ Programmer’s Guide for NonStop Systems429301-008
13-41
HEAP
For native C and C++ programs, you should not specify the HEAP pragma unless
there is an unusual reason to limit the heap size to less than the capacity of the
program address space.
The HEAP pragma specifies an upper bound on heap size by setting the
heap_max attribute in a new loadfile; for example, specifying HEAP n BYTES is
equivalent to specifying -set heap_max n to the eld linker for the loadfile.
You do not need to recompile to change the setting. The HEAP pragma setting and
-set heap_max setting can be replaced later by using the linker command
-change heap_max n filename, where filename designates the program file.
See the appropriate linker manual for information on setting the heap_max flag
with the appropriate number of bytes.
If you do not use the HEAP pragma when compiling a native program with the
RUNNABLE pragma, the compiler leaves the maximum heap size unspecified. This
causes the value used to be determined by the first of the following that has a
nonzero value:
1. The pe_heap_max value assigned to the program file by a process that
launches it
2. The heap_max attribute of the program file
If the heap_max attribute remains zero, all of the user data area (minus that area
used for global data segments and the argv[] and envp[] arrays) is available for
the heap.
If you do use the HEAP pragma when compiling a native program, the space
specified must be sufficient to contain at least the global data segments and the
argv[] and envp[] arrays.
The maximum size of native user heap can be affected by the use of operating
system memory segments:
°
Flat segments are allocated in the same area, downward from its upper bound.
°
Certain products allocate segments in the same area, causing address
collisions when certain features are used; the QIO Configuration and
Management Manual provides guidance on one such instance.
°
DLL text and data segments can be loaded into the same area.
When such segments already exist, the heap area is bounded by the start of the
segment with the lowest address. An attempt to allocate a flat segment or load a
DLL can fail if the heap has already consumed the area needed.
Heap growth, like the allocation or growth of other data segments, will fail if
insufficient swap space is available for the processor.
If your program causes a run-time error message that it is out of virtual memory, try
increasing the swap file space available to it, following the guidelines in the Kernel-
Managed Swap Facility (KMSF) Manual.