LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

queue or array which is better?

Solved!
Go to solution

I need a array of clusters to be stored for which the length is not defined. I will update, Add new element to it.

Array or queue can be used to store the clusters. Which one would be better to use in terms of memory usage, fast execution and other performance parameters.

 

I have some other doubts also. 

Consider an array of 8 elements. When an new element is added to the array using 'insert into array', 

whether a new copy of 9 elements will be created? or 9th element will be linked after the 8th element (like linked lists)? or something else happens?

If a new copy is created, what happens to old 8 elements in the memory, whether that memory will be freed or kept as such?

The same doubt in case of queue also...

 

Thanks in advance.. 

0 Kudos
Message 1 of 6
(5,344 Views)

In your case, you want to use a queue. 

An array is stored in RAM in consecutive memory locations. When increasing the size of the array, the data structure is increased in size and often entirely moved to a place where it can all fit. If you are resizing an array inside a fairly fast loop, the performance hit would be noticeable.

A Queue is able to place individual elements in their own address chunks in RAM and is much more performance-friendly.

 

_____________________________
- Cheers, Ed
0 Kudos
Message 2 of 6
(5,319 Views)

if you want your array to be a FIFO I think the queue is the better choice, but if you need to insert a element at a particular place in the array then array would be better.

Rodéric L
Certified LabVIEW Architect
0 Kudos
Message 3 of 6
(5,314 Views)

I also need to search for a particular element and remove it. 'Search 1D array' will be useful here.
In my case, Array may suit my purpose. I think, it is better to predefine the size of the array for memory concern. 

 

Is there any way to update a particular element/delete in a queue?

 

@Roderic Thanks.

I do not want to insert element at particular place. I need to append to array,update an existing element in the array and remove any element in the array.

0 Kudos
Message 4 of 6
(5,285 Views)

you can define an index in the replace and delete subset functions

_____________________________
- Cheers, Ed
0 Kudos
Message 5 of 6
(5,282 Views)
Solution
Accepted by topic author lxkarthi

Well as far as I'm aware, you can't remove an element at a particular place, or you'll have to dequeue element, store them, delete the particular element then enqueue all elements. So IMO you should use an array for your application.

Rodéric L
Certified LabVIEW Architect
0 Kudos
Message 6 of 6
(5,271 Views)