Guardian Programmer's Guide

Table Of Contents
Managing Memory
Guardian Programmer’s Guide 421922-014
17 - 14
Managing the Native User Data Areas
unnamed process and set the upper bound of the main stack to 10 megabytes. The
example sets the mainstack^max parameter to 10000000D.
STRING PROG_NAME[0:ZSYS^VAL^LEN^FILENAME-1];
INT .EXT ERROR_DETAIL,
OUTPUT_LIST_LEN;
STRUCT OUTPUT_LIST(ZSYS^DDL^SMSG^PROCCREATE^DEF);
STRUCT PARAM_LIST(PROCESS_LAUNCH_PARAMS);
.
.
PARAM_LIST ':=' P_L_DEFAULT_PARMS_; !initialize param struct
PROG_NAME ':=' "PROGFILE" -> @S^PTR; !program file name
@PARAM_LIST.PROGRAM^NAME := $XADR(PROG_NAME);
PARAM_LIST.PROGRAM^NAME^LEN := $DBL(@S^PTR '-' @PROG_NAME);
PARAM_LIST.NAME^OPTIONS := ZSYS^VAL^PCREATOPT^NONAME;
PARAM_LIST.MAINSTACK^MAX := 10000000D;
ERROR := PROCESS_LAUNCH_(PARAM_LIST,
ERROR_DETAIL,
OUTPUT_LIST:$LEN(OUTPUT_LIST),
OUTPUT_LIST_LEN);
See Section 16, Creating and Managing Processes, for more information about calling
PROCESS_LAUNCH_.
To set the main stack size using NLD, specify the mainstack_max option when
invoking NLD. The following example uses NLD to set the maximum size of the main
stack to 10 megabytes:
NLD -SET MAINSTACK_MAX 10000000
Increasing the Size of the Main and Priv Stacks
The main and priv stacks are assigned an initial size by the operating system at
process creation time. The main stack then grows as needed during process
execution, up to the value of the MAINSTACK^MAX process attribute. Because the
main stack is managed for you, you seldom need to be concerned about the amount of
stack space available at any given time. However, in cases where stack space is a
concern, you can use the HEADROOM_ENSURE_ procedure to ensure that there is
enough space, or “headroom,” in the stack for the needs of your process.
The priv stack is not adjusted automatically, but because it is used only by system
library procedures, a nonprivileged procedure generally has no need to call
HEADROOM_ENSURE_ to increase the size of the priv stack.
When calling HEADROOM_ENSURE_, you specify the number of bytes you think you
will need in the stack. (The current size of the main stack is contained in the
MAINSTACK^SIZE attribute, which you can check by calling the
PROCESS_GETINFOLIST_ procedure.) HEADROOM_ENSURE_ then checks the
size of the stack, attempts to enlarge it if necessary, and returns one of the following
values:
A value of zero indicates that either there was already enough room or the stack
was enlarged to make enough room.