arraysplcsiemenstia-portal

Pros and cons of using arrays of one element vs single variables


I would like to understand what is the difference in the PLC performances if I declare and use an array of one element or a single variable.

I am reusing parts of a TIA Portal project where all the variables were indexed. In the project I am working on, there is no need to have arrays, but keeping the indexes would keep the parts of code I am using identical.

Does the array use more resources? Are there any limits on the hardware? In short, are there any cons in keeping the arrays of 1 element?

Thanks in advance


Solution

  • I do not believe arrays have any memory overhead in work memory, but they require extra processing time if they are being indexed with variables.

    I don't know if there's any processing overhead if arrays are indexed with constants (in your case, 1). I would guess not, but if you want to be sure, create some one-element arrays and perform 100s or 1000s of math operations on them in a loop. Then use the RUNTIME instruction to compare the processing time with a copy that uses simple variables instead. I have used this method in the past to compare the efficiency of different types of operations.