LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the lifetime and loading of subvis (newbie)?

Just learning LV and wondering about subvis. Can a subvi be thought of just like a "C" function? Lets split the discussion into two areas: diagram (code) and controls (variables). Are the following statements true or false.

Diagram (code):
Same as in "C". Subvi diagrams load at the same time as the top level vi?
Do they stay in memory until top level vi stops and unloads?

Controls (variables):
Are controls not explictly passed into the subvi like local variables in "C". Every time you call the subvi their state can not be counted on (depends on the current stack)?
Do these extra controls always get inited to their default values for every call?
Do these extra controls only get inited to their defau
lts when the subvi loads into memory?
Do these extra controls remember their state between calls to subvis (like a local static variable in "C")?

Thanks for your help. I've had a hard time finding this type of information. Any pointer to a good source would be apreciated.
Kurt
0 Kudos
Message 1 of 2
(2,185 Views)
My responses are marked with a ***.

> Just learning LV and wondering about subvis. Can a subvi be thought
> of just like a "C" function? Lets split the discussion into two
> areas: diagram (code) and controls (variables). Are the following
> statements true or false.


*** A subVI and a C function are very similar in the way they are used,
but different in the details. As you will see, in some respects they
are like DLLs.


>
> Diagram (code):
> Same as in "C". Subvi diagrams load at the same time as the top level
> vi?

> Do they stay in memory until top level vi stops and unloads?


Statically linked subVIs are loaded by the linker when the top-level VI
loads. If they cannot be located, the top-level VI is broken. The
subVI can be refernced multiple times by multiple top-level VIs, so each
of these counts as a reference. VIs can also be loaded and unloaded
dynamically using the VI server. At that point subVIs are loaded when
the reference is opened. SubVIs leave memory when the last reference,
both static and dynamic goes away.


>
> Controls (variables):
> Are controls not explictly passed into the subvi like local variables
> in "C". Every time you call the subvi their state can not be counted
> on (depends on the current stack)?
> Do these extra controls always get inited to their default values for
> every call?
> Do these extra controls only get inited to their defaults when the
> subvi loads into memory?
> Do these extra controls remember their state between calls to subvis
> (like a local static variable in "C")?
>


Controls not connected to the connector pane get initialized when the VI
first comes into memory. The control values are maintained across calls
the way that static variables do.

Controls on the connector pane are part of the calling interface. They
have either the wired value or the default. Similar to C++ default
parameters, but without the ordering issues.

This won't completely answer the questions, but opening the panel with
the application running will demonstrate what I've told you. You can
hit the pause button on the subVI to slow things down a bit.

Greg McKaskle
Message 2 of 2
(2,185 Views)