07-23-2015 09:33 AM
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
07-23-2015 09:43 AM - edited 07-23-2015 09:43 AM
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!
07-23-2015 09:46 AM
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
07-23-2015 09:49 AM
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!
07-23-2015 10:43 AM
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.
07-23-2015 11:33 AM
@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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
07-23-2015 03:02 PM
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