LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Arrays: Build array in multiple for loops or replace array elements

I need to build a 3D array (200X100X100) or I can programatically replace array subsets in an existing initialized array of dimensions 200X100X100.

I was wondering if there are any memory advantages to using build arrays VIs in multiple for loops with shift registers or whether it is advantageous to replace array elements.
0 Kudos
Message 1 of 5
(3,324 Views)
There is a distinct speed advantage to using Replace Array Element as opposed to using the Build Array function. With the Build Array, LabVIEW has to keep resizing the array buffer. This can add a lot of extra time for large arrays. This specific subject is discussed in the LabVIEW Performance and Memory Management pdf document that is part of the LabVIEW Bookshelf.
Message 2 of 5
(3,324 Views)
This was the standard answer before LV 6i.

LV is pretty good about guessing how much space should be allocated and will do this ahead of time.

I did not trust this info when I first read it in the release notes for 6i.

So...
I sat down and wrote a bench mark to compare my "allocate and replace" vs "for loop with auto-indexing". There used to be (prior to LV 6i) a big diffence in the performance.

The two method are now virtually identical!

Note:
This test was done using a 1-d array. I did not bench mark multidimensional arrays.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 5
(3,324 Views)
I followed Dennis' advice about using replace vs. build array VIs.

For the 200X100X100 array Labview allocates ~25MB of memory vs. 100MB. So the savings with replace array appears sub substantial.

Thanks for both of your replies.
0 Kudos
Message 4 of 5
(3,324 Views)
The other aspect of this question is execution time. And in general the answer Dennis gave is best from that standpoint as well.

Still it is sometimes valuable to test assumptions. For example, I found out on a project once that doing something the "wrong" way five or six time could take a lot less time than doing it the "right" way five- to six-hundred times.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 5
(3,324 Views)