LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
Adament_C_Programmer

Labview Static Variables and VI Instances

Status: Declined
LabVIEW supports this through reentrancy with pre-allocated clones.


Labview has a way of creating the equivalent of static variables in a VI similar to static variables in OO languages or function-scoped static variables in C. This way is through the use of uninitialized shift-registers in single-iteration loops (i.e dummy loops).

If multiple instances of a VI is created and the VI contains such a static variable, the value of the static variable persists from one instance to the next. I can see why this is useful, but I think it would also be useful if there was an option to make static variables of different instances of a VI separate.

Static variables are primarily useful for VIs that have some concept of state and you don't want to explicitly create a state variable or cluster that the user has to manually feedback with outside signals. For example, if you created a VI for a PID controller or a state machine, and you wanted to use an uninitialized shift register to store that state, you can not create multiple instances of that VI with out having the two instances intefere with each other. The two instances cannot maintain independent state.

I ran into this problem while creating a VI to implement a moving window of values. (as a side not, it would be useful to have a moving window VI)

6 Comments
tomlawton
Member

Check out "reentrancy"

CMal
Active Participant

As tomlawton suggested, marking a VI with "Preallocated clone reentrante execution" will do exactly what you want.  In fact, this is preciesely what the VIs in the PID toolkit do to prevent multiple instances from sharing state data.  More information about reentrancy can be found here.

crossrulz
Knight of NI

The LabVIEW Field Journal had a good series on this topic.  You really should give it a good read.  The first installment can be found here:http://labviewjournal.com/2012/02/maintaining-state-1/


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
Dragis
Active Participant
Status changed to: Declined
LabVIEW supports this through reentrancy with pre-allocated clones.
Dragis
Active Participant

I closed the idea as already supported.  If there is a specific use case that existing support doesn't cover, please create a new idea with that use case defined more explicitly.

Adament_C_Programmer
Member

Thanks folks! I'm a labview newb so excuse the silly idea. I really appreciate the quick and helpful response though. Happy holidays!