LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does this sample vi use so much memory?

I'm working on a effort to reduce memory use of a large LabView application. The attached test vi seems simple enough - initialize a 3-D array (8x7x4320) to an I32 value, and display it. By my reasoning, the array should use 8x7x4230x4 bytes = 967,680 bytes. The array indicator should use that much more. But when I run this with the Profiler, it shows 3,871,572 bytes being used, twice as much as I'd expect. What am I missing!?
0 Kudos
Message 1 of 6
(3,321 Views)
The default values?

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 6
(3,321 Views)
Sorry - I don't understand your answer.
0 Kudos
Message 3 of 6
(3,321 Views)
Hidden behind the scenes is a copy of the default value of the control.

When you do a "save as default" there is a copy made of the data.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 6
(3,321 Views)
mlayton,

Avoiding large arrays being copied is an art in LabVIEW. This time the LabVIEW compiler is too smart trying to optimize the code. When you use "Initialize Array" with all constants on input, LabVIEW creates the array at compile time and saves a copy of the initialized array. When copied to the indicator, that makes two copies.

To prevent one copy, replace one of the constants (8,7 or 4320) with a FP control with the same default value. Then the array will be created at run-time only.

Do not display the array in an indicator if you can avoid it as LabVIEW makes a copy for the indicator display. The user doesn't need to see the 967,680 values. If you need an indicator to pass the array to its caller, LabVIEW will manage to reuse the arra
y space if the subVI always keeps its FP closed (no need for display).

If the large array is to be used everywhere in the application, it can be stored in the shift register of a subVI. In this subVI, put all the code required to manipulate the array (Initialize/Read/Write/ elements, etc). That will greatly reduced te number of unnecessary copies of the array.


LabVIEW, C'est LabVIEW

Message 5 of 6
(3,321 Views)
Here is a template for large array storage/manipulation. As you can see, the array exists only in the shift register of the VI. Is is manipulated "in place" without unnecessary copies being passed to/from. The element is a typedef so it is easy to adapt the code to your array type (and add dimensions...).


LabVIEW, C'est LabVIEW

Download All
0 Kudos
Message 6 of 6
(3,321 Views)