LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

enqueue multiple arrays as one big array

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!

0 Kudos
Message 1 of 6
(3,227 Views)

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.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 2 of 6
(3,219 Views)

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?

0 Kudos
Message 3 of 6
(3,211 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 6
(3,179 Views)

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

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 5 of 6
(3,163 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 6
(3,146 Views)