LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best practices when using loops

Hi all,

 

I have a question regarding best practices when using loops. Suppose that I have a sub-VI with several inputs (big arrays and clusters) which are used within loops, let´s say for loops. Now suppose that I pass the inputs to the sub-vi from a main VI. Some of those inputs might be used to define the number of iterations, but some not as they are only read (imagine they ara just clusters of parameters).

Where and how is the best place to locate the controls holding the inputs in the sub-VI? 

a) Inside the loop. (Does this mean that the sub-vi has to read the control in every iteration?)

b) Outside the loop with a tunnel? (suppose the input is not modified in the array). (Should these make a copy of the input in every iteration?)

c) Outside the loop with a shif register?

d) other way.

 

Thanks in advance for your help,

Best regards,

Esteban

0 Kudos
Message 1 of 7
(3,217 Views)

Hi Esteban,

 

controls should be placed outside of any loop. They even should be placed outside of any structure…

 

They only belong inside the loop(s) when they can change their value while the loop runs: This certainly will not happen in your subVIs once the values are supplied by the mainVI!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(3,204 Views)

Hello GerdW,

 

Thanks for your prompt reply.

What about the difference in placing them as tunnels or shift registers? Does that have an impact on the memory usage?

 

Regards,

Esteban

0 Kudos
Message 3 of 7
(3,198 Views)

Hi Esteban,

 

when you just read the value from the wire (without modifying it) there will be no difference…

 

Shift registers become important when your loop can run zero times as they behave different to tunnels in such cases!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 7
(3,189 Views)

Arroyo wrote:  What about the difference in placing them as tunnels or shift registers? Does that have an impact on the memory usage?

As a rule, I use shift registers for references, just to avoid the FOR loop ran 0 iterations scenario (you will lose your reference if you used tunnels).  Everything else generally does not care.


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
0 Kudos
Message 5 of 7
(3,151 Views)

@crossrulz wrote:

As a rule, I use shift registers for references, just to avoid the FOR loop ran 0 iterations scenario (you will lose your reference if you used tunnels).  Everything else generally does not care.


Oh another good one is the error wire.  It should also usually be a shift register because if the for loop runs 0 times, the error would be cleared, which might not be what you want.

0 Kudos
Message 6 of 7
(3,130 Views)

This thread from 9 years ago touches on a similar question.

 

In that thread Greg McKaskle (now in the most lfty tower at NI) explains WHY controls on the icon connector should not be inisde structures and the effect on memory, defualt values etc.

 

Ben

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