07-29-2013 01:53 PM
I would like to enqueue multiple arrays of various length into one queue. When the length of this array is n, I will dequeue and read all the elements (as one single array).
I tried using the initialize queue method with an array as the data type, and enquing the arrays as I receive them.
However the result is a cluster of arrays, and not one big array as I want.
I tried it with enqueing elements(of each array) one by one, and it works. the only problem is that when the arrays get long it will have to loop many times to enqueue everything and slows down my program.
So is there a way to enqueue multiple arrays as one big array?
So if:
arr1=[1 2 3]
and arr 2 = [4 5 6]
the output should be: [1 2 3 4 5 6]
Thanks!
07-29-2013 02:12 PM - edited 07-29-2013 02:18 PM
It doesn't sound like you want to use queues for this, if I understand you correctly.
You can enqueue multiple small arrays to a larger array but you won't know when the total number of elements equals 'n' without polling the queue and adding the number of elements in each. I'd suggest a producer-consumer VI where you enqueue the small arrays in the producer and constantly dequeue and concatenate them in the consumer. Let the consumer loop decide when to operate on the concatenated array.
Keep in mind that concatenating arrays can become memory-intensive and slow your system as the array grows larger. If you know how large the array will be, you can pre-allocate it and replace array subsets instead of concatenating.
07-29-2013 02:25 PM - edited 07-29-2013 02:26 PM
Thanks,
I am going try to the producer/consumer model as you suggested. I found the VI template, but how many producer loops do I need? And what should be the stop condition for the consumer loop?
Yes the aray size will grow larger (and the program will be running for long periods of time).And I do not know the final size.
But since I am dequeing(or emptying) the array every once in a while does it make any difference?
07-29-2013 05:21 PM
ou do know a fixed size for your array. You had indicated you only want to process the array once you have n number of elements. Preallocate the array in the consumer to be n + some small amount for to allow you to receive a segment of your array that will push you over the threshold but have some elements remaining. You can decide whether to buffer them for the next processing or process them with this data.
07-29-2013 08:19 PM
@developer001 wrote:
Thanks,
I am going try to the producer/consumer model as you suggested. I found the VI template, but how many producer loops do I need? And what should be the stop condition for the consumer loop?
Yes the aray size will grow larger (and the program will be running for long periods of time).And I do not know the final size.
But since I am dequeing(or emptying) the array every once in a while does it make any difference?
I'd think you only need one producer loop, unless you have multiple sources producing data to be enqueued. A cheap-and-dirty, but effective, method for stopping your consumer loop is to kill the queue in the producer and let the consumer stop on the dequeue error.
07-30-2013 01:33 AM
Assuming some producer/consumer structure, use 2 commands, 1 for Enqueue (simple build array) which checks if the resulting array is >=N in which case you enqueue the resulting array with a Dequeue-command.
/Y