09-21-2016 06:33 PM - edited 09-21-2016 06:34 PM
Hi,
I using the function Obtain Queue, and the data type is an array of string.
I pass arrays with no more than 10 elements (maximum) and the max lenght of string is 15 chars.
I would like to restrict the queue's size to 5 arrays with characteristics above, so what is the value that I have to inpput in Max queue size? 5?! or 5x10x15=750?
Obs: I'm using this queue to run in CompactRIO RT. I read that this function only limits the size, but doesn't prealloc memory. Is it correct?
Solved! Go to Solution.
09-21-2016 06:37 PM
I would say 5, because the queue element is an array of string and you want up to five of those.
It would be simple to create a small test VI to verify. Try it. 😄
09-21-2016 08:45 PM
@jonesjol wrote:Obs: I'm using this queue to run in CompactRIO RT. I read that this function only limits the size, but doesn't prealloc memory. Is it correct?
The Obtain Queue does not allocate memory. All it can do is limit the number if places in the FIFO. So if you want to limit 5 arrays to be in the queue, then you wire up a 5.
If you want preallocated memory, then you need to use an RT FIFO. However, they do not work with dynamically sized data types (arrays, strings).
An alternative to your array of strings would be to use a cluster of bytes. Since you want a 10 element array of strings with 15 characters, that would be 150 bytes. Not sure it is really worth it here.
09-22-2016 05:55 AM
As others have said, if you only want 5 arrays in the queue, then set Max Queue Size to 5.
You can "preallocate" memory by filling the Queue (after the Obtain Queue Function), then use the Flush Queue Function to clear it. But this is a small queue, so I can't see a benefit in doing this.
Be aware that a fixed size queue has unique characteristics.
As altenbach mentioned, you can (and should) make an simple test vi to see how it works.
What happens if you use the normal Enqueue Element Function when you try to add a sixth element? (Hint: The -unwired by default- timeout in ms (-1) input makes a difference.)
There is a Lossy Enqueue Element Function. What happens when you add a sixth element using this function? Is this the functionality you want?
If you do a little test and figure out the answers to these questions you will probably know how to implement the queue for your program. You did not say why you wanted to do this, so it's hard to give you specific advice.
If you run into trouble, just ask (and include your test code).
steve
09-22-2016 06:12 AM - edited 09-22-2016 06:21 AM
@stevem181 wrote:You can "preallocate" memory by filling the Queue (after the Obtain Queue Function), then use the Flush Queue Function to clear it.
Actually by using the Flush, you just deallocated the memory you just "preallocated". That's right, the Flush clears all of the data memory of the queue. That is why there is a trash can as part of the icon.
If you really want to do the preallocate, use a FOR loop to fill up the queue and then another one to dequeue all of the elements.
But since we are talking about non-fixed data type (arrays and strings!), I do not think the preallocation trick will actually help any.
09-22-2016 06:19 AM
Try this which gives how the queue behaves wrt to size.
12-16-2016 09:40 AM
Actually, the statement "The Obtain Queue does not allocate memory" is not correct when used in an RT environment:
Help-> Note (Real-Time Module) max queue size preallocates the specified number of elements in the queue when running on an RT target.
I came at this topic because I was searching for details about this preallocation, but the existence of the preallocation is a fact.
12-16-2016 02:16 PM
@Bert_INCAA wrote:
Actually, the statement "The Obtain Queue does not allocate memory" is not correct when used in an RT environment
Not quite. The Obtain Queue does not allocate the memory, even in RT. The RT FIFO preallocates the memory. Big difference between a "normal" queue and an RT FIFO.
12-17-2016 06:00 AM
12-17-2016 07:11 AM
I was specifically told by NI SE that the Obtain Queue on RT does not preallocate the memory. I'll see what presentation data I can dig up. And now I wish I had my myRIO to experiement. Perhaps on Monday...