LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Coding pattern: Branching an array wire, vs. passing it through a loop?

Hello,

 

In the diagram below, the purple wire is branched just before it enters the timed loop.

 

I was wondering: Will there be any difference if, instead of branching, I take the output of the Read Variable VI and tunnel it back out (with auto-indexing)?

 

Thanks!

Certified LabVIEW Developer
0 Kudos
Message 1 of 4
(2,904 Views)

Hello JKSH,

 

Branching array wires leaves the possible of LabVIEW creating data copies, so if possible, I would avoid it.  You can use the "Buffer Allocation"tool to confirm that a data copy will or will not occur.

 

Untitled.png

 

However, in the example you have shown, the code on the right of the time structured is unreachable since the timed structure will never exit ("False" is hard wired to the conditional terminal).

 

In addition, the array that is passed into the "For Loop" inside the Time structure, I'm pretty sure you're going to want change the tunnels to shift registers.  Otherwise, the only thing that is going to come out of that "for loop" is an array full of 0's except for the last element will be populated with the value from the shared variable.  (Maybe that's what you want but then why use a For loop to read all the elements Smiley Wink

Message 2 of 4
(2,887 Views)

@gt8860a wrote:

Hello JKSH,

 

Branching array wires leaves the possible of LabVIEW creating data copies, so if possible, I would avoid it.  You can use the "Buffer Allocation"tool to confirm that a data copy will or will not occur.


Thanks for the tips, gt8860a!

 

With the specific example in my original post, if I use the pass-through wire from the Read Variable VI, would it cause the inner for-loop to rewrite the output array (of variable references) at every iteration of the outer timed loop?

 


@gt8860a wrote:

However, in the example you have shown, the code on the right of the time structured is unreachable since the timed structure will never exit ("False" is hard wired to the conditional terminal).

 

In addition, the array that is passed into the "For Loop" inside the Time structure, I'm pretty sure you're going to want change the tunnels to shift registers.  Otherwise, the only thing that is going to come out of that "for loop" is an array full of 0's except for the last element will be populated with the value from the shared variable.  (Maybe that's what you want but then why use a For loop to read all the elements Smiley Wink


Good catch; I didn't notice those. The example was from official NI documentation:

 

http://zone.ni.com/reference/en-XX/help/371361G-01/lvconcepts/switchtoprogsvaccess/ 

http://zone.ni.com/reference/en-XX/help/371361G-01/lvconcepts/usingdynvarapi/ 

 

How do we get them corrected?

Certified LabVIEW Developer
0 Kudos
Message 3 of 4
(2,870 Views)

Hello JKSH,

 

I believe if you passed the reference out to the border of the inner for loop and enable Indexing, it will recreate the output array on every iteration.

 

You could try this if you don't want to recreate the array every iteration.

 

Untitled.png

As for correcting the example, I have no idea how to get that done.  Maybe a moderator will read this thread and take the intiative.

 

Message 4 of 4
(2,858 Views)