It is written, that also not edited task programs can change their local memory position. Which means pointers gets invalid.
- Does that also mean, that if a not edited task gets moved, the Init and Exit Program does not run?
- And if the init and exit does not run, what about allocated memory via TMP_alloc? Is that also invalid in that case?
- If the not edited task is getting moved, means that the memory is cleared or does the transfer save the old values and copy it to the new location?
1 Like
Hi,
first I’ve to mention that I only share my own experiences and what I know about, but I don’t have deep insights (like for example a AR developer has).
It is written, that also not edited task programs can change their local memory position. Which means pointers gets invalid.
Yes, it could happen under some special circumstances, that, while downloading software changes, even a task that has not changed and therefore is not transferred, changes it’s memory position in DRAM.
I personally know this from the following concrete use-case:
- the code of a library is changed, but the library’s instance / interface does not change
- one (or more) task uses for example a function block out of this library.
- Because of the unchanged library interface/memory, the task is not recompiled (for the task, nothing has changed)
- when transferring the changed library, the task has to be “unloaded” temporary (because he references a function block from this changed library)
- after the library was transferred, the task is loaded again an executed
- → Now, the task has changed it’s DRAM memory location
- Does that also mean, that if a not edited task gets moved, the Init and Exit Program does not run?
Yes, INIT and EXIT are only executed when PLC is booted (INIT), or a download of the task itself is performed (EXIT and INIT, depending on the transfer settings).
- And if the init and exit does not run, what about allocated memory via TMP_alloc? Is that also invalid in that case?
As I know, TMP_alloc and AsMem() aren’t influenced and stay valid, because those functions are allocating the memory out of the systems free DRAM, and the operating system itself administrates this memory allocation.
- If the not edited task is getting moved, means that the memory is cleared or does the transfer save the old values and copy it to the new location?
Which memory do you mean exactly, the local IEC variables (“process variables”)? As I know their values are kept.
Best regards!
1 Like
If a memory location is moved by the system, the program using that memory should be notified. This allows the program to take appropriate action and avoid unexpected behavior. It becomes problematic when the system relocates memory without informing the program that depends on it, as this can lead to errors, crashes, or data corruption.
This is especially relevant in cases such as changes to a library, as you mentioned. When developing a PLC program, the programmer must account for all such scenarios, since the system is not capable of notifying the program before performing a memory relocation.
In practice, we often see that some programmers do not consider all these edge cases, leading to serious issues. For example, PLCs may enter service mode during data transfer or exhibit other faulty behavior as a result of such oversights.
Hi,
I can’t say if something like that is in preparation or even technically possible, but from my understanding such a signaling would not solve every topic, for example topics around priority-based task interruption, performance topics (nothing is faster then a flat memory access), and some other.
As I know, there’s exactly one case where a memory movement without transfer can lead to problems: accessing a variable by it’s address, that is not done cyclically. So making the needed ACCESS in CYCLIC instead of in INIT will prevent access violations caused by moved memory.
But maybe I’ve overseen something: what are your conrete use-cases, where memory movement without transfer leads to issues? And what programming language(s) do you use (I’m asking because of the usage of C/C++, where not only IEC variables are possible, but also “pure C variables”, which is maybe a different story)?
Best regards!
1 Like