Stack size [number of bytes]
Title short form | Stack size |
Categories | Informative, efficient, reliable |
Definition | Number of bytes required to call a function or function block |
Further information | Input variables and output variables are aligned with the memory. This can create a gap between these variables and the local variables. This gap is counted. Return values from called functions that do not fit into a register are pushed onto the stack. The largest of these values determines the additionally allocated memory, which is also counted. Functions or function blocks that are called within the POUs under consideration have their own stack frame. Therefore, the memory for such calls does not count. Depending on the code generator used, intermediate results of calculations also use the stack. These results are not counted. |
Sample:
FUNCTION F_Sample : INT
VAR_INPUT
a,b : INT;
END_VAR
VAR
c,d,e : INT;
END_VAR
VAR_STAT
f,g,h : INT;
END_VARc := b;
d := a;
e := a + b;Assumption: The "TwinCAT RT (x86)" solution platform is used for the calculation. The device has a stack alignment of 4 bytes, which can result in gaps between the variables.
The total stack size of F_Sample is 16 bytes and consists of:
- 2 input variables with 2 bytes each = 4 bytes
- No padding bytes
- Return value INT = 2 bytes
- Padding bytes for the stack alignment = 2 bytes
- 3 local variables with 2 bytes each = 6 bytes
- Padding bytes for the stack alignment = 2 bytes
VAR_STAT is not stored on the stack and therefore does not increase the stack size of a POU.