LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to replace extra local variables

Solved!
Go to solution

2 while loops are okay. 2 dozen means something is wrong fundamentally with your existing architecture.

 

You must rewrite it anew.

- Partha ( CLD until Oct 2027 🙂 )
0 Kudos
Message 11 of 29
(2,608 Views)

It sounds as though it is time to reorganize your program.  With that many loops I suspect that the program has grown over time without any thought or planning given to the overall architecture.

 

Queues are good ways to pass data between loops, but you will have a lot of queues with as many loops as you have.  Action Engines may be a better choice, because they can be read many places.

 

Lynn 

Message 12 of 29
(2,627 Views)
Solution
Accepted by topic author hellolv

There are five items you can use to replace local variables - in order of preference:

  1. Wires - never use a local when a wire will do
  2. Shift registers - fast and local
  3. Data value reference - new in LabVIEW 2009
  4. Single-element queue or action engine - these are equally good, interchangeable in most situations, use the one which fits your programming style and circumstances (I use both but prefer the former for most things)
I have deluged you with enough information.  Good luck!
Message 13 of 29
(2,606 Views)

DFGray wrote:

There are five items


Where is the fifth? Smiley Wink

 

But I know it is NOT Property node. Smiley Very Happy

- Partha ( CLD until Oct 2027 🙂 )
0 Kudos
Message 14 of 29
(2,600 Views)
I believe the fifth is hidding in the fourth.....
0 Kudos
Message 15 of 29
(2,598 Views)
Thanks for the masterpiece!  What is the best way to write to a single element queue?  Dequeue first then Enqueue?
0 Kudos
Message 16 of 29
(2,582 Views)

DFGray wrote:

There are five items you can use to replace local variables - in order of preference:

  1. Wires - never use a local when a wire will do
  2. Shift registers - fast and local
  3. Data value reference - new in LabVIEW 2009
  4. Single-element queue or action engine - these are equally good, interchangeable in most situations, use the one which fits your programming style and circumstances (I use both but prefer the former for most things)
I have deluged you with enough information.  Good luck!

The Single-element queue might be overkill for replacing local variables which have been tested and do not have race conditions. If the code is written in such a way that race conditions can't happen, then I think the native functions Notifier or Queue would be a better choice for the sake of simplicity. This is just an opinion, and is notwithstanding the Data value reference option.  

 

 

Richard






0 Kudos
Message 17 of 29
(2,562 Views)


Got about two dozens of while loops running in parallel and bunch of data needs to be flowing back and forth between them.
 


Maybe a proper use of conditional case in a single loop will help your cause (just a guess).......
0 Kudos
Message 18 of 29
(2,524 Views)

You are correct.  To write to a single-element queue, dequeue first, change or replace the value, then enqueue.  Reading is similar.  Dequeue, then enqueue.  Since the first act is always a dequeue and there is only one element, this serves as a global mutex, also giving you atomic operation properties.  Remember to enqueue or other readers will halt.  The fact that you have a "mutex" also opens you up to deadlock possibilities.  The safe use of global data is a minefield.  Let us know if you need more help.

 

P.S.  The fourth and fifth methods are listed in my fourth item.  They are distinctly different methods, but are equally useful, so I grouped them together since the list was by order of preference.

 

P.P.S.  I do not consider the replacement of locals (or globals) by data value references, single-element queues or action engines to be overkill in any situation, provided the options above these in the list are not useable.  I would much rather have the flexibility of encapsulating code into subVIs at will and controlling access to the variable.  This is not an option with locals.  However, this is a personal preference.  My code tends to be extremely modular.

0 Kudos
Message 19 of 29
(2,511 Views)
In order to Read, I was considering Preview the queue.....
0 Kudos
Message 20 of 29
(2,504 Views)