C/C++ Programmer's Guide (G06.25+)
Running and Debugging C and C++ Programs
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
19-7
Two Memory Models: Large and Small
Two Memory Models: Large and Small
HP TNS C has two memory models: the large-memory model and the small-memory 
model. HP TNS C++, native C, and native C++ has only the large-memory model.
Both models support large amounts of code, but the large-memory model also 
supports large amounts of data. You cannot mix modules compiled with different 
memory models; all modules in a program must be compiled for either the small-
memory model or the large-memory model. Table 19-2 summarizes the characteristics 
of each memory model. Figure 19-1 on page 19-8 illustrates the memory models.
HP strongly recommends that your TNS C programs use the large-memory model.
Small-Memory Model
The small-memory model uses 16-bit addressing and stores all data in the user data 
space, which can contain up to 64 KB.
The primary global area contains global scalar variables, scalar variables that are local 
to a function but are declared as having storage class static, and pointers to global 
aggregates that reside in the secondary global area. (A scalar type is a character, an 
integer, an enumeration, or a floating point type. An aggregate type is an array or 
struct.)
The heap area is reserved for dynamic memory. The heap is managed by the 
calloc(), free(), malloc(), and realloc() library functions.
The stack area is reserved for the run-time stack. The stack area stores local variables. 
Its size is 64 KB minus the size of the heap and the global area.
Large-Memory Model
The large-memory model uses 32-bit addressing. It stores the heap and the global and 
static aggregates in a single extended memory segment. Here, static aggregate refers 
to an aggregate that is declared with the static storage class specifier. Both global 
and static aggregates have storage class static, which means that they retain their 
values throughout the execution of the entire program.
Table 19-2. Memory Models
Memory 
Model
Size of 
Code Space
Size of
Data Space
Size of 
Pointer Available in
Small 4 MB 64 KB 16-bit Guardian environment for TNS C 
programs only
Large 4 MB 127.5 MB 32-bit Guardian and OSS environments 
for all C and C++ programs










