Dan123 said:
...I came upon the information that using DINTs is more efficient than using SINTs or INTs...Is this also true for arrays and UDTs?...
It's to do with the fact that the Logix processor uses a 32-bit architecture and how selecting different data types affects the utilization of memory according to the 32-bit boundaries. This also effects how efficiently the processor can access that memory. Each data type you select, regardless of whether a BOOL, SINT, INT or DINT will be stored in a 32-bit memory allocation. So if you create a tag of BOOL data type, it will use up 32 bits of memory, but only one bit is usable, the other 31 are wasted, so to speak. If you create a tag of DINT data type, all 32 bits can be utilized as BOOL by addressing to the bit level within the DINT (DINT.0, DINT.1, etc.). This way there is no waste, as such, and access is faster.
Do not use BOOLEAN arrays. Apart from being inefficient memory wise, they are not well supported instruction wise.
To expand on Bernie's info...
It's better to create a UDT with 32 BOOL members. You'll notice that if you create a user defined structure of BOOL less than 32, it will automatically expand it to 32. The UDT will align its data to the 32-bit boundaries. So, if 32 BOOL members within the UDT, each will be stored in contiguous bits to fill the first 32-bit boundary. The same applies to SINT, aligning to the first 8 bits. So as advised, pack these in together, so 4 x SINT, for instance, would take up 32 contiguous bits. 2 x INT = 32 bits, etc. DINT natively store to within the 32-bit boundary. That is why they are the recommended data type to use.
Dan123 said:
...would an array of 10 SINTs (12 bytes) be more efficient than an array of 10 DINTs (40 bytes) since they are grouped together?
Maybe it's just a typo, but just to clear up what a "byte" is...
1 byte = 8 bits
1 SINT = 1 byte
10 SINT = 10 bytes (
not 12 bytes)
An array of 10 SINT, or 10 x 8 bits, will use up 10 x 32-bit memory allocations, aligning 8 bits into the first 8 bits of each 32-bit boundary. This uses up 320 bits of memory, to utilize 80 bits, wasting 240 bits. That's 320 bits the processor has to access just to use 80 bits.
The array of 10 DINT beats this hands down. Again, this array will use up 10 x 32-bit memory allocations, but the DINT will fill up all 320 bits, wasting none.
It's mainly about organizing your data to be efficient in the use of memory so as to speed up the processors native access to that memory, but it's also about saving space for the future.
Regards,
George