12-18-2014 01:29 PM
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?
12-18-2014 01:41 PM
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.
12-18-2014 01:43 PM
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.
12-18-2014 01:48 PM
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.
12-18-2014 01:52 PM
Attached what you should do. Don't pass your array control reference, just a reference to the data is alright.
12-18-2014 01:52 PM
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.
12-18-2014 02:02 PM
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.
12-18-2014 02:13 PM
@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?
12-18-2014 02:26 PM
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.
12-18-2014 02:37 PM - edited 12-18-2014 02:37 PM
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.