BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Why some people say Local Variables are bad...

RJay,

 

In a nut-shell.

 

never use a local if you pass the data with a wire.

 

If a wire will not do it, try a shift register.

 

If the data has to be shared between multiple loops a method of sharing a shift register between threads is an Action Engine as I discuss in this Nugget.

 

If you "data path" has a single "reciever, use queues to pass the data.

 

Locals can be used effectively if you need to write to a control but should not be used as a technique for sharing data.

 

I hope that helps,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 81 of 395
(12,855 Views)

While we're on the topic of Local abuse..  To illustrate Ben's point, the code shown below could SHOULD have used shift registers instead of locals.

 

 

 

from:  http://forums.ni.com/ni/board/message?board.id=170&view=by_date_ascending&message.id=360264#M360264

Message Edited by JoeLabView on 10-09-2008 09:08 AM
Download All
0 Kudos
Message 82 of 395
(12,853 Views)

... there's more...

 

 

Message Edited by JoeLabView on 10-09-2008 09:09 AM
Download All
Message 83 of 395
(12,850 Views)

From:  http://forums.ni.com/ni/board/message?board.id=170&thread.id=362300

 

Plus, there is more abuse in the code.. 

 

Message 84 of 395
(12,772 Views)

I downloaded a bit of sample code from a pump manufacturer which claimed to have the hardware 'drivers'. I thought I'd best take a look to be safe, but it was just a simple demo of how to use VISA to communicate over RS232. Fair enough, LV is very different to text languages so a demo is always nice and helpful.

 

HOWEVER, the VI which does all the communicating business is a 3 frame stacked frame structure which uses both local variables to pass the VISA reference and sequence locals to pass the error cluster through all the frames. Additionally, the 'first call' primitive is used to open the VISA reference first time through, but at no point is the close VISA reference called, leaving the LV RTE to free memory.

_____________________________
- Cheers, Ed
0 Kudos
Message 85 of 395
(12,596 Views)

We bought an old rig from one of our other sites with the intention of adding some post process processes to it. The accompanying hardware manual is thick, in depth and very well laid out with cross references that match up with each other and everything. It even includes the manuals for third party hardware - RS232, GPIB devices and such. My task is to add all the the extra functionality, and - hooray! It is supplied with the source code! Given the quality of the hardware manual, I was expecting the software to be of a similar standard. Ho ho ho, I think not....

 

 

There are dozens of Sub VIs and they all look like that. The code has been crammed into the view of a 1024*768 screen. All in all there are 331 Global variables, 188 local variables and 79 stacked or flat sequence structures,

 

Message Edited by yenknip on 01-07-2009 05:14 PM
_____________________________
- Cheers, Ed
Message 86 of 395
(12,428 Views)

Well, that's an example of taking the "No diagram bigger than the screen size" a LITTLE too far.

 

I always think of "rules" like this as being quite elastic.  You can bend them quite far without actually breaking them  :smileyvery-happy:

 

OTOH, the Local usage is horrendous.....

 

Shane

0 Kudos
Message 87 of 395
(12,397 Views)

I like how there's a front panel control called "Gunk". 

 

-D

Message Edited by Darren on 01-08-2009 02:23 PM
Message 88 of 395
(12,379 Views)
It's always amusing to see a Global going to a Local.  Maybe they get paid by the number of Global + Local useage. 
Message 89 of 395
(12,322 Views)

Interesting way to split the error cluster.  It doesn't show the entire code, but I bet the error clusters are joined using Locals..  Just a guess..  maybe..

 

http://forums.ni.com/ni/board/message?board.id=170&thread.id=393756

 

 

Message 90 of 395
(11,981 Views)