LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Large Arrays by Reference

I am trying to conserve memory in my program by passing a ref to a subvi for a large data array.  Inside the subvi, I want to access directly some of the array elements. Is there a way to do this without reallocating memory space for the entire array?  I attempted to simulate a solution using the inplace element structure below.  Will this do it or am I breaking the rules here?  

0 Kudos
Message 1 of 13
(4,190 Views)

You are actually making things worse.  Just pass the array in, use the In Place Element Structure to manipulate the values you need to, and then pass the value back out.  That will no cause any copies of the array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 13
(4,185 Views)

thanks but I need to "not modify the existing data element value".  I need to simply extract an elements value for some other VI input.

0 Kudos
Message 3 of 13
(4,181 Views)

Then just use Index Array and/or Array Subset.  But making the reference to the control to then extract the value is actually making a copy of the array and causing a thread swap, which really slows down your system.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 13
(4,171 Views)

Attached what you should do. Don't pass your array control reference, just a reference to the data is alright.

0 Kudos
Message 5 of 13
(4,165 Views)

The VI you wrote will make a copy because of your use of front panel references. You can delete the ref, the create DVR, and the inplace node. Just wire Huge Array straight to the index array and it won't make a copy of the array. It will make a copy of the indexed string.

0 Kudos
Message 6 of 13
(4,164 Views)

That's why I suggest him to pass a DVR to the subVI, inside the subVI he can manipulate the DVR without making any array copy.

0 Kudos
Message 7 of 13
(4,151 Views)

@id wrote:

I am trying to conserve memory in my program by passing a ref to a subvi for a large data array.


You are almost there, except that your VI does not represent the sceanrio you are describing.

I guess you have your huge array in the main VI and want to access some elements in the subVI.

 

Your word "ref" can mean many things, so you should be more specific. In this particular case you would create a data value reference in the main VI and wire the data value reference to the subVI. In the subVI, you just take the reference and use the rest of your code to get the desired element.

 

It really depends on the details, but sometimes you could also just inline the subVI. Can you attach a more realistic example of what you are trying to do?

0 Kudos
Message 8 of 13
(4,143 Views)

Here u go Ben.  I am simply calling a subvi.  I want to not alter the array data in place as I need to pass this dataset to many other functions for their own processing on the dataset as tehy were designed to operate on teh original dataset array.

 

 

Download All
0 Kudos
Message 9 of 13
(4,115 Views)

Do not make a DVR of the control reference.  That is making a reference to a reference.  Instead, make the DVR of the data itself.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 13
(4,105 Views)