CRE Programmer's Guide
CRE Services
Common Run-Time Environment (CRE) Programmer’s Guide—528146-004
2-43
Using the Native Heap Managers
Requesting Space on the Heap
C routines request heap space by calling the C malloc() function, and return heap 
space by calling the C 
free() function. pTAL routines do the same. C++ routines 
request heap space by calling the 
new() function, and return heap space by calling 
the 
delete() function.
Accessing Heap Data:
•
C, C++, pTAL routines can reference data allocated on the heap by storing the 
address of the data into a pointer and referencing the pointer in an expression.
•
A pTAL routine can call a C or C++ routine to allocate or free heap space. The 
following code fragment shows a pTAL routine, Do_It, that calls a C routine, 
GETSPACE, to get space from the heap. GETSPACE gets a block from the heap 
and stores a value in the first 16-bit word of the block. When GETSPACE returns, 
its value is a pointer to the newly allocated block. Do_It reads the value stored by 
GETSPACE. The C routine is shown first:
#include <stddef.h> nolist
#include <stdlib.h> nolist
int *GETSPACE( int nbytes )
{ int *p;
 p = (int *) malloc( nbytes )
 if (p != NULL) *p = 100;
 return p;
}
The following pTAL code calls the C routine GETSPACE:
INT(32) PROC TAL_Malloc = "GETSPACE" ( nbytes ) LANGUAGE C;
 INT(32) nbytes;
EXTERNAL;
PROC Do_It;
BEGIN
 INT .EXT T_Ptr;
 @T_Ptr := TAL_Malloc( 1000D );
 IF (@T_Ptr = OD) OR (T_Ptr <> 100) THEN
 BEGIN
 ! Handle error...
 END;
END;
Using the Native Heap Managers
Beginning at the G06.15 release, the native CRE includes two heap managers:
•
The high-performance heap manager, contained in product T1269G09 
(NSK CRE/RTL). 
The new heap manager is available only for programs that use the native CRE; 
this includes native C, native C++, and ECOBOL or NMCOBOL programs. 










