pTAL Conversion Guide

pTAL Built-In Routines
pTAL Conversion Guide527302-002
18-45
$STACK_ALLOCATE
size
is an INT expression that specifies the number of bytes to allocate. size is an
unsigned value from 0 through 65534. $STACK_ALLOCATE rounds size up to the
next integral multiple of 8 if it is not already an integral multiple of 8.
$STACK_ALLOCATE returns a WADDR address, which is the lowest address in the
allocated memory. The address returned by $STACK_ALLOCATE is an integral
multiple of 8.
$STACK_ALLOCATE does not clear the allocated data area.
$STACK_ALLOCATE does not return error conditions, but stack overflow can occur
within $STACK_ALLOCATE or on a subsequent procedure call from within the
procedure that calls $STACK_ALLOCATE.
When a procedure or routine returns to its caller, the system deallocates all memory
allocated by $STACK_ALLOCATE within that procedure.
pTAL does not support calls to $STACK_ALLOCATE from subprocedures and reports
a syntax error if it encounters one. From within a subprocedure, however, you can
reference data in a block allocated in the encompassing procedure.
Within each call of a procedure, the location of the block allocated on the first call to
$STACK_ALLOCATE is independent of the location of the calling procedure’s local
data. In particular, the first block allocated and the procedure’s local data are not, in
general, contiguous. On subsequent calls to $STACK_ALLOCATE within the same
procedure call, however, each newly allocated block and the previously allocated block
are contiguous. (Note, however, that the compiler might insert filler items in order to
better align data in the block.)
pTAL privileged procedure No
Can be executed only by privileged procedures No
Sets condition code No
Sets $CARRY No
Sets $OVERFLOW No
Example 18-34. Call to $STACK_ALLOCATE Routine
INT .p(template);
INT(32) .a;
INT(32) i32;
...
@p := $STACK_ALLOCATE($LEN(template));
@a := $STACK_ALLOCATE($LEN(i32)* 10);