LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Do Controls/Indicators in Subvi terminals translate to dynamically allocated memory?

Hi,

 

I want to create a set of subVIs which will operate within an existing while loop structure. As these will be deployed on an embedded device, I want to conserve and re-use as much memory as possible - meaning I don't want to allocate copies of variables if I don't have to. My question is this:

 

When creating a subVI and connecting output terminals to controls or input terminals to indicators within the subVI, does the software make copies of the information as it comes in or is it operating on the same space in memory pointed to by the original variable? If the first case, how can I change it to make the input variables not get copied when they enter a subVI?

0 Kudos
Message 1 of 8
(3,270 Views)

Good Question!

 

In this thread (see reply #12 for the meat) you will find where we discussed just that topic and found a big difference in performance between these two constructs.

 

 

If you look close the only difference is where you place your terminal.

 

Have fun,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 8
(3,258 Views)

So is the incoming outgoing data from a terminal only "copied" if the terminal indicator/control is placed inside a structure? Can you confirm that placing the terminal on the root of the diagragm ensures that data won't be copied? I think that's what the other thread concluded but being a beginner and not fully understanding the lingo involved, I just wanted to confirm.

0 Kudos
Message 3 of 8
(3,250 Views)

@kgolden wrote:

So is the incoming outgoing data from a terminal only "copied" if the terminal indicator/control is placed inside a structure? Can you confirm that placing the terminal on the root of the diagragm ensures that data won't be copied? I think that's what the other thread concluded but being a beginner and not fully understanding the lingo involved, I just wanted to confirm.


Aside from running that same bench-mark code in that thread, no I can't confirm. Alos keep in mind that if the wire in the caller branches when calling the sub-VI, data copy.

 

I use "Show Buffer Allocations*" as another method to show where my buffers are being created.

 

Ben

 

* from memory.... Tools >>> Performance >>> Show Buffer Allocations ????

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 8
(3,245 Views)

This is what I got from "show buffer allocations." The VIs in gray are my sub VIs. It appears that they are not re-allocating memory on their inputs based on this.

showbuffer.JPG

0 Kudos
Message 5 of 8
(3,228 Views)

I don't think you can conclude anything from this image, because the data is allocated in the subVI, not the main VI.

 

There is also a difference if the front panel is loaded into memory (subVI front panel shown, property nodes present, etc.)

 

Is your subVI re-entrant?

0 Kudos
Message 6 of 8
(3,223 Views)

I'm really not sure if it's re-entrant because I use controls inside the subVI to bring in the data from the terminals. I thought re-entrant to mean that it works on data provided meaning it operates on the same location in memory as its parent function. Other than that, the subvi creates no specific data of its own other than what I'm trying to bring in from the outside. I guess the equivalent in text based programming for what I'm trying to do is "pass by reference" so as not to copy unneccessary data. On the other hand, I wonder if even "pass by reference" copies data (the memory address) into a new memory location? If so, it may defeat the purpose since the data I'm actually dealing with here is doubles.

 

Your post brings another point regarding the front panel. How can this be disabled? Is simply making the controls and indicators "not visible" enough to keep the front panel out of memory for subVIs?

0 Kudos
Message 7 of 8
(3,209 Views)

Hi kgolden,

 

Reentrancy is a property of the VI found by going to File » VI Properties » Execution.  Also, you are correct in your thinking about reference passing in text-based programming: it will copy the memory address of the data.  However, since addresses are 32 bits and doubles are 64 bits, you would save four bytes of data.  This may not be worth any performance hit, though.

 

Controls and Indicators will always be in memory when a VI is running since they are part of the VI.  You can think of them as local variables for the subVI similar to local variables in text-based.

Jared S.
Applications Engineering
National Instruments
0 Kudos
Message 8 of 8
(3,178 Views)