LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Doubt about Max queue size in Obtain Queue

Solved!
Go to solution
Highlighted

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?

0 Kudos
Message 1 of 11
(1,855 Views)

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. Smiley Very Happy


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 2 of 11
(1,849 Views)
Solution
Accepted by topic author jonesjol

@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.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 3 of 11
(1,816 Views)
Solution
Accepted by topic author jonesjol

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

--------------------------------------------------------------------------------------------------------------------------
Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help.
--------------------------------------------------------------------------------------------------------------------------
Message 4 of 11
(1,788 Views)

@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.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 5 of 11
(1,784 Views)

Try this which gives how the queue behaves wrt to size.

Queue.png

Palanivel Thiruvenkadam,
CLA|| CTD
0 Kudos
Message 6 of 11
(1,781 Views)

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.

0 Kudos
Message 7 of 11
(1,497 Views)

@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.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 8 of 11
(1,481 Views)
ok, that's your bet against the help description, see for example http://zone.ni.com/reference/en-XX/help/371361J-01/glang/create_queue/
0 Kudos
Message 9 of 11
(1,466 Views)

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...


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 10 of 11
(1,458 Views)