LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Global variable, local and property node

Hi!

 

I have basic question:

1. What is the difference between the use of local variable and using property node (provided it is linked to an appropriate variable)?

2. What exactly is global variable and local variable?

 

I try to read its definition.. But I could not get the meaning.

 

Thank you.

 

0 Kudos
Message 1 of 10
(6,767 Views)

Use global variable if you need to access a variable from different VI's/Sub-VI's.

Local Variables you can access them only from the VI you have created them.

 

Hope that helps...

 

Dimitrios

0 Kudos
Message 2 of 10
(6,762 Views)

If you can use local variable or property node is better to use local variable because is faster.

But if you can avoid both of them by connecting wires that's much better practice.

 

Dimitrios

0 Kudos
Message 3 of 10
(6,756 Views)

Have a look at that explanation also

 

What is the Difference Between a Local Variable and a Value Property Node?

http://digital.ni.com/public.nsf/allkb/74ECB57D3C6DF2CE86256BE30074EC47

 

 

Message 4 of 10
(6,750 Views)

Thanks Dimitrios!

 

I will read the link you gave me, 

about global variable, I am still a bit confuse..

 

0 Kudos
Message 5 of 10
(6,748 Views)

There is possibility that local variables creating race conditions

 

Why some people say Local Variables are bad.

 

Are globals really THAT evil?

Message 6 of 10
(6,742 Views)

Ok, lets say you have 2 different independent programs saved as Untitled1.vi and Untitled2.vi.

When run Untitled 1 is doing some calculations. At the same time you run in parrallel Untitled 2 that does some other jobs but in order to do them it needs to know the result of those calculations. Then you would write the results of those calculations to a Global variable on Untitled1 and you will read the same global variable on Untitled 2.

 

If you can use only one VI (let's call that Untitled3.vi) that does both the calculations from Untitled1.vi and the jobs from Untitled2.vi (using a flat-sequence for example)then you may pass the results of the calculations to a local variable (if that's the best way - not always).

 

Then you can read that local variable on the same block diagram to do the other jobs you want.  

 

Not the best example but difficult to put it into words.

 

0 Kudos
Message 7 of 10
(6,721 Views)

First of all, the equivalent of variables in traditional languages are wires. So whenever possible pass the data via wires!

 

Local variables are useful if you need to programatically inialize a control. Property nodes (value) allow to do the same inside a SubVi via a control reference, but they are much slower.

Globals are fast and can be used for look-up tables or 'global settings'. You should make sure they are initialized at the beginning of your program and never written again (Single writer). 

 

Globals ans Locals can be misused as means to communicate between parallel tasks, but using queues or LV2 globals is a far better approach. 

 

Felix 

Message 8 of 10
(6,716 Views)

The code described by Dimitrios is a perfect example of a bad usage of local variables. All this can be done by using a wire. And this also eliminates the need for a sequence, because the execution is determined by dataflow.

 

Felix 

Message 9 of 10
(6,696 Views)

Here is a Nugget on Action Engines (LV2 globals) that discusses the issues with race conditions and how they can be avoided.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 10 of 10
(6,692 Views)