I expect the bottleneck is rather the CPU and not the memory. I heard you mention memory concerns before, but I am a bit surprised by this actually. I don't see how our PLCs would be even remotely constrained by memory at the moment. The CPU on the other hand is very perceivable as a limited resource. In my example above I'm running at 48% CPU usage with a 5ms cycle time but I'd prefer to go faster than this. Why should I be concerned about memory usage, too? Also, I am not familiar with the memory model of the TwinCAT PLC runtime, but it might be a small comfort that the large struct array can be implemented as VAR CONSTANT. This way, if "replace constant" is active the whole data can go into the code or text memory and doesn't have to be on the heap. At the same time, since the methods are much smaller and a lot of the text (in particular the event additional text strings) is not compiled into the code or text area anymore, the overall memory usage should actually be quite similar! I ran the original version and my proposal through my project and got the following compiler output (although I am not 100% sure what these numbers mean and whether they can be trusted and are meaningful): Memory area Original New Proposal Generated code 2084112 2066608 Global data 4300269 4321077 Total (code and data) 7086832 7090136 Special memory (IO, persistent etc) 128000 128000 So the code memory goes down by 20000 and data goes up by 20000. It seems that the compiler either doesn't take the "replace constants" very seriously or the data area also encompasses the text area and that's where the big structure is stored. Anyway, overall it seems bigger by less than 4kB. And a 0.05% increase in memory seems like an acceptable price for 1% CPU 😅 This is a bit off-topic now, but just writing about the "replace constants" settings, is there a recommendation from BCI which setting should be used and if so, is there some documentation that says so and why?
... View more