LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to iniitialize a queue with array elements

Solved!
Go to solution

Hi Guys

 

I'm looking for a bit of performance optimization..  

I'm developing a noise measurement application using LV8.6 and Win Xp /Win 7.

To put it very simple I have a loop that samples, and a loop that does the math. data is shipped in a queue, producer / consumer style.

So far so good.. Question is - is there a specific and more optimized way to declare this queue?

I was wondering if declaring the queue with an initialized array element of a fixed size (the number of samples pr. read from the sound card will be known at runtime) would produce a queue that would be less heavy on dynamic allocation of memory compared to a queue obtained using a simple control no values.

 

I've attached a screen dump to maybe make the question more obvious..

 

I've been thru the "clear as mud" thread, as recommended in other threads that covers this topic - but i gets very high tech, and I kind of lost my way in it.. So looking for a more simple "you should use solution #x, because..."

 

Thank you in advance.screen dump 

0 Kudos
Message 1 of 8
(9,029 Views)

you should use solution # 2 because Initializing an array first and then replacing its elements allocates all the necessary memory at once as opposed to rearranging memory as the array grows in size. 

0 Kudos
Message 2 of 8
(9,015 Views)
Solution
Accepted by topic author Navne

H Sh wrote:

you should use solution # 2 because Initializing an array first and then replacing its elements allocates all the necessary memory at once as opposed to rearranging memory as the array grows in size. 


What does your answer have to do with a queue?

 

Using option 2 will not do a thing about creating a queue with a fixed number of elements. With either, you start with an empty queue. If you used an empty array constant with option 1, then that would require less memory in the VI itself. If you wanted to set the queue size, wire something to that input.

Message 3 of 8
(9,005 Views)

Oh yes my mistake.. In queue there is no replacement of elements as it will enqueue the elements at the end.. so no need to allocate the size in starting infact of no use and will unneccessary holds some memory..

 

so solution #1 is better option..

0 Kudos
Message 4 of 8
(8,979 Views)
Thanks guys - I'l stick with solution 1, which is also what has been in the code so far and running well. 
0 Kudos
Message 5 of 8
(8,903 Views)

Wire into the queue element data type input a build array function with 2 elements (say 0 and 1) also works.

0 Kudos
Message 6 of 8
(7,997 Views)

@jcannon wrote:

Wire into the queue element data type input a build array function with 2 elements (say 0 and 1) also works.


(Why so complicated? It would work equally well with a build array function with a single input, or even with an empty array diagram constant.)

 

Any array of the desired datatype will work, no matter how you create it. Only the type is important, the data is ignored.

 

 

0 Kudos
Message 7 of 8
(7,989 Views)

I believe (but am not sure) RT FIFOs will allocate this memory for you ahead of time. But, remember they are not deterministic on windows. You need to wire an array constant of the correct size into the FIFO read function also to avoid memory allocation, which is easy to overlook. It's worth looking into, if nothing else, assuming you have RT functions available. WIth this method, the queue size needs to be set, and you run the risk of overflowing and losing elements if not handled correctly. 

 

Just throwing other options out there.

0 Kudos
Message 8 of 8
(7,983 Views)