Guardian Programmer's Guide

Table Of Contents
Managing Memory
Guardian Programmer’s Guide 421922-014
17 - 21
Using Selectable Segments in TNS Processes
statements; use of the MOVEX procedure is not required. Depending on the
number of SEGMENT_USE_ and MOVEX calls in your program, removing them
can provide a significant performance enhancement.
Flat segments provide access to more virtual memory and enable you to access
areas of memory that were previously inaccessible.
Flat segments are more convenient from a programming standpoint, because
programs do not need calls to SEGMENT_USE_ or MOVEX.
If you have more than one selectable segment, you should use flat segments to
prevent performance degradation when switching between selectable segments,
because only one selectable segment is visible at a time. Flat segments are
always visible.
TNS processes using the automatic extended data segment should avoid selecting
other segments; see the following section.
You might still want to use selectable segments to simplify migration to newer systems
or for programs to be executed on both older and newer systems.
Using Selectable Segments in TNS Processes
Many TNS processes use an automatic extended data segment, a selectable segment
with ID 1024. It is created implicitly by the TNS C, Fortran and Pascal compilers when
using the large-memory model (XMEM, often called the LARGE or WIDE model in TNS
C). The TAL compiler also creates the automatic extended segment if any aggregate
variables (structures and arrays) are declared with extended indirection (.EXT). By
default, C places the heap, most global and static variables, and local aggregate
variables in the extended segment; the default can be overridden through use of the
_lowmem storage specifier. The automatic segment is selected when the process
starts, and remains selected unless some other segment is selected.
HP recommends against explicitly calling SEGMENT_USE_ or USESEGMENT to
select other selectable segments in TNS processes that use the automatic extended
data segment. Explicit segment selection is possible, but fraught with difficulty: When
the program selects some other segment, the automatic segment becomes invisible,
so the heap and many variables become inaccessible. Any reference to one of these
areas becomes a reference to the same address in the currently selected segment,
leading to incorrect program behavior and likely data corruption. Therefore, the
programmer must avoid making any such references while the other segment is
selected. Also, the program must avoid calling any functions that depend on the heap.
That set of functions is not explicitly documented, but includes many common ones,
such as printf(). If explicit segment selection is necessary, limit the duration of the
selection to as few statements as possible, and ensure that those statements refer only
to local scalar variables or variables qualified by the _lowmem storage specifier; avoid
calling most run-time library functions. Immediately reinstate the automatic segment
by selecting the previously selected segment, using the ID returned via the old-
segment-id parameter to SEGMENT_USE_.