Metric: Stack Size

User Description

An application or library is organized by complex types such as programs, function blocks, global variable lists, methods, actions, functions, structures, and so on. Inside each of these types, variables can be defined.

When a complex type like a function, method, action, property Get, property Set, or a transition is called, memory on the stack is needed to execute the method. The stack size information can be used to identify the complex type which is using too much memory of the stack.

NOTE: Stack memory that is available per task is limited and defined by the controller used. Large consumption of stack size can result in exceptions.
NOTE: If a function block type is used as method input variable type (call by value), the memory size of the complex type is needed (refer to Memory Size Data). Do not use call by value for complex types like method or function inputs.

Metric Calculation

For a complex type like function or method, the sizes of the variables are summed up. When the complex type is called, the size is allocated on top of the stack and the input values are copied the allocated memory. During the code execution of the function or method, these memory values are used.

NOTE: Each method or function call has its own memory and does not conflict if a method is called in parallel by another task.

Example

Stack Size calculation example:

FUNCTION_BLOCK FB_XXX
VAR
    fbComplex: FB_Test; // 20 byte
END_VAR

// method call of FB_XXX
Meth1(TRUE);

METHOD Meth1
VAR_INPUT
   xTest1: BOOL;
END_VARVAR
   iTest2: INT;
END_VAR


METHOD METH2
VAR_INPUT
    fbComp: FB_XXX;
END_VAR

Stack Size Results

Stack Size (METH1) = 8
Stack Size (METH2) = 32