LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it ok to use local variables within the same loop?


@billko wrote:

@David99999 wrote:

Would a channel writer/reader setup be better than a local variable for sharing data between loops?


Probably over a billion times better, but I didn't check the math on that.


I ran the numbers a while back and it's actually 1,000,000,000.33 (repeating, of course).

Message 11 of 22
(1,495 Views)
@David99999 wrote:

Would a channel writer/reader setup be better than a local variable for sharing data between loops?

Channel wires were created to communicate between loops and they do it really well. Start here. I use them all the time for simple tasks like this and for much more complex message/actor-based architectures, and they always do their job, as well as make the code more readable.

 

Certified LabVIEW Architect
Message 12 of 22
(1,465 Views)

@David99999 wrote:

Would a channel writer/reader setup be better than a local variable for sharing data between loops?


That depends on the channel wire type.

 

If you use a 'tag' channel wire (basically a current value), I don't think there's much difference regarding race conditions.

 

But once you start putting things in sub VIs (not possible with locals), at least you have a wire to track.

 

If you use a messenger or stream, the loops are synchronized, and you probably might as well use 1 loop.

0 Kudos
Message 13 of 22
(1,454 Views)

wiebe@CARYA wrote:

 

If you use a messenger or stream, the loops are synchronized, and you probably might as well use 1 loop


I don't believe this is true. 

 

What about a stream in a Producer/Consumer or SMH architecture?

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 14 of 22
(1,414 Views)

@RTSLVU wrote:

wiebe@CARYA wrote:

 

If you use a messenger or stream, the loops are synchronized, and you probably might as well use 1 loop


I don't believe this is true. 

 

What about a stream in a Producer/Consumer or SMH architecture?


I think Wiebe went too generic in his comment.  From other conversations I have had with him, I'm pretty sure he was trying to refer to "Synchronous Communication" where loop 1 sends a command/request to loop 2 and then waits for a reply.  This is a form of synchronization that would make one think about if multiple loops is actually needed.



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
Message 15 of 22
(1,394 Views)

@RTSLVU wrote:

wiebe@CARYA wrote:

 

If you use a messenger or stream, the loops are synchronized, and you probably might as well use 1 loop


I don't believe this is true. 

 

What about a stream in a Producer/Consumer or SMH architecture?


In the context of the use case OP is picturing...

example

instead of a local, use a stream\messenger channel wire between two loops makes little sense (to me)...

 

0 Kudos
Message 16 of 22
(1,372 Views)

wiebe@CARYA wrote:


In the use case OP is picturing...


Sure, but the OP's cases are not real world cases.

 

But they are common mistakes of using locals

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 17 of 22
(1,364 Views)

@RTSLVU wrote:

wiebe@CARYA wrote:


In the use case OP is picturing...


Sure, but the OP's cases are not real world cases.

 

But they are common mistakes of using locals


I concur...

0 Kudos
Message 18 of 22
(1,338 Views)

Hi,

Local variable is not advisable to use inside the same loop. Instead you can use Functional Global variable. i have attached a reference of your code based on FGV. kindly refer that.

0 Kudos
Message 19 of 22
(1,239 Views)

@Magesh003 wrote:

Hi,

Local variable is not advisable to use inside the same loop. Instead you can use Functional Global variable. i have attached a reference of your code based on FGV. kindly refer that.


While an FGV would work here, it is completely unjustified. Just use the wire. Think dataflow!

thols_0-1651754057184.png

 

Certified LabVIEW Architect
Message 20 of 22
(1,228 Views)