RsLogix Integer Type Efficiency

Dan123

Member
Join Date
Sep 2014
Location
California
Posts
17
While designing a project in RSLogix5000, I came upon the information that using DINTs is more efficient than using SINTs or INTs (Reference thread: http://www.plctalk.net/qanda/showthread.php?t=6826).

Is this also true for arrays and UDTs? The RSLogix Design Considerations document recommends grouping integers into arrays/UDTs. By doing this, would an array of 10 SINTs (12 bytes) be more efficient than an array of 10 DINTs (40 bytes) since they are grouped together?
 
When I create a complex UDT I place all BOOLs first followed by SINTs then INTs then DINTs. After that I place any arrays or other UDTs. Regardless of type these always end on 32 bit boundaries so they will always nest efficiently.
 
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
 
Do not use BOOLEAN arrays. Apart from being inefficient memory wise, they are not well supported instruction wise.

Bool arrays are actually efficient memory wise. You have to create arrays in multiples of 32 and those bits are packed so each multiple of 32 uses a single 32-bit memory space. If you create a bool array and specify a size that is not a multiple of 32, the size is adjusted to the next multiple. Create an array of 100 bools and it will change it to 128 automatically.

But, I would definitely agree that it is not well supported by the instruction set.

OG
 
Sorry,

OG, you are correct.

I don't know why I said "...Apart from being inefficient memory wise,..." for BOOL arrays? I must have been thinking ahead of myself or something. I actually outlined what you just said in how user defined structures auto change BOOL arrays to 32-bit boundaries!

Geospark said:
...You'll notice that if you create a user defined structure of BOOL less than 32, it will automatically expand it to 32...

Thanks again,

G.
 
When I said 12 bytes, I was referring to page 45 from the Design Considerations document (see below), which is also what you were saying 4 x SINT will take up 32 contiguous bits. From this, it appears that an array of 10 SINTs will use less memory than an array of 10 DINTs.

I understand that using standalone SINT or INT tags are inefficient because they need to be mapped to 4 bytes anyway -- therefore execution time and memory usage to access the tag is much greater than using DINT tags (see PDF below). I just wanted to know if the same is true for arrays and UDTs because the document isn't clear.

To provide context, I have a project where I need a ton of integers that have a maximum size of 100 -- and many of these integers will be in arrays and UDTs. I am also reading and writing to these tags through OPC. Using SINTs make the size of the UDTs smaller than if I used DINTs -- which is good UNLESS the execution and communication time of SINTs inside arrays and UDTs is just as bad as standalone SINTs. In that case, I would just use DINTs in all my UDTs and not worry about the size of them.
 

Similar Topics

I've got a Keyence barcode scanner I've got coming in via Ethernet to a Micrologic 1100. I've got the data coming into N Type Data Files and when...
Replies
12
Views
7,030
Hello, I've got a tricky math problem. I have a double integer that I need to divide by 10,000, and separate it into quotient and remainder. I...
Replies
9
Views
7,501
We are having intermittent problems with the transfer of data in a sequence of events where the data is being lost or overwritten and the problem...
Replies
9
Views
5,936
If I have an integer, lets say N7:0 with a value of 10 in it, what's the simplest way to covert it to ascii and put it A29:700? My attempts at...
Replies
4
Views
4,998
Hello all, I have a question in regards to RSlogix 5000. I am having issues with the program force closing when I try to make online edits. We...
Replies
0
Views
95
Back
Top Bottom