LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it more effecient to pass constants (such arrays or scalars) into a loop or to put them inside the loop to use?

What is the difference between putting an array constant or control outside a loop and passing it in or putting it inside a loop to use?
0 Kudos
Message 1 of 3
(2,649 Views)
If you read an array control or local/global inside the loop, the value of the array is read at each iteration since its value might have changed since the previous iteration. That may be useful if you are polling the value for changes. If you know that the value is constant, or want to read it only once, then it is better to read the value outside the loop and wire it inside. It is sure that the content of the tunneled data won't change so the same copy is reused.

For diagram constants, LabVIEW migth be smart enough to use them like a tunnel but it is still safer to read them outside the loop. You can check for yourself if there is a performance hit from reading a constant array from inside or outside a loop.


LabVIEW, C'est LabVIEW

Message 2 of 3
(2,649 Views)
> If you read an array control or local/global inside the loop, the
> value of the array is read at each iteration since its value might
> have changed since the previous iteration. That may be useful if you
> are polling the value for changes. If you know that the value is
> constant, or want to read it only once, then it is better to read the
> value outside the loop and wire it inside. It is sure that the content
> of the tunneled data won't change so the same copy is reused.

All implementations are subject to change, but for the moment, here are
the details. Reading from a control's front panel terminal is quite
smart about whether the data has been modified. Locals aren't, and
always copy. Globals aren't and always copy. Constants cannot b
e
changed at runtime and shouldn't have any difference inside or outside
the loop.

My opinion is to put it outside if the wire is short, inside if it would
make a long wire.

Greg McKaskle
0 Kudos
Message 3 of 3
(2,649 Views)