StackSize Parameter
Default Value: 4096
Minimum Value: 32
Maximum Value: 131072
Units: None
Type: int
Use the StackSize parameter to specify the maximum size of the program stack that is available for the selected task. The parameter value specifies the number of 64-bit words that is allocated for the program stack. The program stack is a separate area of memory than the string stack, which is used to store memory for values that are returned from functions and string concatenations. To configure the string stack, use the StringStackSize Parameter. Local variables, function arguments, function calls, and calls to property get and set accessors use space on the program stack. Examples of local variables include:
- Variables that you declare in a program block.
- Variables that you declare in a function block.
- Arguments that you declare for a function.
- Values that you return from a function. String values that you return from a function use the string stack instead of the program stack.
- Variables that you declare in a get or set accessor block of a property.
- Variables that you declare in a conditional block (if statement, switch statement).
- Variables that you declare in an iterative block (while loop, for loop).
- Variables that the controller automatically declares when you use a foreach loop to iterate over the array that you specify.
Some memory of the program stack is consumed when the controller executes a block for a program, function, property get or set accessor, conditional statement, or iterative statement that contains local variables. Some memory of the program stack is released when the controller finishes executing a block that contains local variables. The memory of the program stack can be exhausted and cause a stack overflow error in some cases. If a stack overflow error occurs, then do one or more of the following:
- Change local variables to program global variables by moving their declaration to outside of any blocks for a program, function, property get or set accessor, conditional statement, or iterative statement. Program global variables are accessible everywhere in the program.
- Declare smaller local variables by reducing the string capacity of string variables or by reducing the dimension sizes of array variables.
- Declare fewer local variables.
- Avoid calling functions, property get accessors, or property set accessors recursively.
- Increase the value of the StackSize parameter.
Each local variable can consume a different number of values in the program stack. Refer to the table that follows to determine how many 64-bit values each local variable consumes on the program stack.
Table: Program Stack Usage Per Local Variable Type
Local Variable Type | Number of Values |
---|---|
integer | 1 |
real | 1 |
axis | 1 |
enum | 1 |
handle | 1 |
string | Varies (refer to String Variables) |
struct | Varies (refer to Struct Variables) |
Array variables | Varies (refer to Array Variables) |
String Variables
The number of values that a variable declared with the string data type consumes on the program stack depends on the string capacity, or maximum number of characters, of the string. Refer to the formula that follows to calculate the number of values that a variable with the string data type consumes on the program stack.
You can specify the string capacity when you declare a string variable by specifying a value in parentheses after the string keyword. The example that follows shows the declaration of a string variable with a string capacity of 32 characters. A string variable with a string capacity of 32 characters consumes 15 values of the program stack.
var $myString as string(25)
If you do not specify the string capacity of a string variable, the controller automatically assigns the string capacity to be 256 characters. The example that follows shows the declaration of a string variable with a string capacity of 256 characters because the string capacity is not specified. A string variable with a string capacity of 256 characters consumes 131 values of the program stack.
var $anotherString as string
Struct Variables
The number of values that a variable declared with the struct data type consumes on the program stack depends on the size of the struct data type. The size of a struct data type is the sum of the sizes of all member variables of the struct data type.
The example that follows shows the declaration of a struct data type. The size of the struct data type is 2 64-bit values because it consists of 2 member variables that each consume 1 64-bit value.
$x as real // Consumes 1 64-bit value
$y as real // Consumes 1 64-bit value
end
Array Variables
The number of values that an array variable consumes on the program stack depends on the number of array dimensions and the size of each array dimension.
1-Dimensional Array Variables
Refer to the formula that follows to calculate the number of values that a 1-dimensional array variable consumes on the program stack.
The example that follows shows a 1-dimensional array variable. The array dimension size is 10 elements and the data type of the array is the integer data type, which has a size of 1 64-bit value on the program stack. This array variable consumes 11 values on the program stack.
var $array[10] as integer
2-Dimensional Array Variables
Refer to the formulas that follow to calculate the number of values that a 2-dimensional array variable consumes on the program stack.
The example that follows shows a 2-dimensional array variable. The first array dimension size is 3 elements and the second array dimension size is 5 elements. The data type of the array is the real data type, which has a size of 1 64-bit value on the program stack. This array variable consumes 19 values on the program stack.
// Number of stack values = 1 + (3 · 6) = 19
var $array[3][5] as real
3-Dimensional Array Variables
Refer to the formulas that follow to calculate the number of values that a 3-dimensional array variable consumes on the program stack.
The example that follows shows a 3-dimensional array variable. The first array dimension size is 3 elements, the second array dimension size is 4 elements, and the third array dimension size is 5 elements. The data type of the array is the axis data type, which has a size of 1 64-bit value on the program stack. This array variable consumes 11 values on the program stack.
// Size of the 2nd dimension = 1 + (4 · 6) = 25
// Number of stack values = 1 + (3 · 25) = 76
var $array[3][4][5] as axis
WARNING: Do not edit this parameter from within an AeroScript program. Edit this parameter only in the Configure workspace of AerotechAutomation1 Studio.
IMPORTANT: You must reset the controller for these changes to have an effect.