CRE Programmer's Guide

CRE Services
Common Run-Time Environment (CRE) Programmer’s Guide528146-004
2-41
Native CRE Memory
Accessing Heap Data:
C and TAL 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.
Routines written in COBOL and FORTRAN must call C or TAL routines to
reference heap data.
A TAL routine can call a C routine to allocate or free heap space. The following
code fragment shows a TAL 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 TAL code calls the C routine GETSPACE:
INT(32) PROC TAL_Malloc = "GETSPACE" ( nbytes ) LANGUAGE C;
INT nbytes;
EXTERNAL;
PROC Do_It;
BEGIN
INT .EXT T_Ptr;
@T_Ptr := TAL_Malloc( 1000 );
IF (@T_Ptr = OD) OR (T_Ptr <> 100) THEN
BEGIN
! Handle error...
END;
END;
Heap Statistics:
The TNS CRE maintains statistics that describe heap utilization.
The native CRE does not support statistics that describe heap utilization.
Native CRE Memory
In the native CRE, the data spaces that your program can use to share data are:
The user heap
Global data
The native CRE allocates memory using the same layout in the OSS and Guardian
environments. For a given total amount of memory allocated to a process, however,