You can persist global variables or variables declared locally in a function block
or program. To do this, add the keyword PERSISTENT
to the declaration. In addition, you insert the instance path to this variable in
the persistent global variable list. To do this, click “Add All Instance Paths” in the persistence editor.
Persistence is guaranteed by the following mechanism:
-
The cyclic tasks in which the variable is accessed are determined.
-
At the end of the first cyclic task (in each cycle), the variable is copied to the persistent global variable list.
-
After restarting the controller, the value of the persistent variable is copied to the ordinary variable.
The disadvantage of this mechanism is that memory is allocated both at the place of declaration and at the place of the instance path. This persistent variable has a double memory allocation. Moreover, the data is copied to both places in each cycle. This can be time consuming, especially when large structured values are involved.