In the CodeSys manual we can read that:
"If you declare a local variable in a function block as RETAIN, CODESYS stores the complete instance of this function block in the Retain range (all data of the function block); however, only the declared RETAIN variable is treated as such."
But does someone actually tested? I created a function block with only the following variables:
VAR
Test1: ARRAY[1..50] OF UINT; //100 bytes
END_VAR
VAR RETAIN
Test2: ARRAY[1..50] OF DINT; //200 bytes
END_VAR
My program only implements one instance of this function block. Using SIZEOF
at runtime shows a function block size of 312 bytes
Now, if I right-click on the device, and go to "Device Memory Info", the size of my Retain Data is only 203 bytes.
If the complete instance of the function block is stored in the retain range, I would expect the retain data size to be the same as the function block size (312 bytes), but it isn't, it's only 203 bytes (size of the retain data). Is the manual incorrect?