NI Home > Community > NI Discussion Forums

BreakPoint

Showing results for 
Search instead for 
Do you mean 
Reply
Knight of NI
Knight of NI
Ben
Posts: 16,134
0 Kudos

Re: 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

Ben Rayner
Who is NOT John Galt... yet... just building Rayner's Ridge
Scheduled to close on the new ridge next week!
Knight of NI
Ray.R
Posts: 10,574
0 Kudos

Re: Why some people say Local Variables are bad...

[ Edited ]

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
______________________________________________________________________
Kudos!!!! Gimme Kudos!!!! It's that little golden star on the left below my avatar... :smileyhappy:
Knight of NI
Ray.R
Posts: 10,574

Re: Why some people say Local Variables are bad...

[ Edited ]

... there's more...

 

 

Message Edited by JoeLabView on 10-09-2008 09:09 AM
______________________________________________________________________
Kudos!!!! Gimme Kudos!!!! It's that little golden star on the left below my avatar... :smileyhappy:
Knight of NI
Ray.R
Posts: 10,574

Re: Why some people say Local Variables are bad...

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

 

Plus, there is more abuse in the code.. 

 

______________________________________________________________________
Kudos!!!! Gimme Kudos!!!! It's that little golden star on the left below my avatar... :smileyhappy:
Active Participant
yenknip
Posts: 540
0 Kudos

Re: Why some people say Local Variables are bad...

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

Active Participant
yenknip
Posts: 540

Re: Why some people say Local Variables are bad...

[ Edited ]

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

Trusted Enthusiast
Intaris
Posts: 3,125
0 Kudos

Re: Why some people say Local Variables are bad...

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

Trusted Enthusiast
Darren
Posts: 2,870

Re: Why some people say Local Variables are bad...

[ Edited ]

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

 

-D

Message Edited by Darren on 01-08-2009 02:23 PM
Darren Nattinger, CLA
LabVIEW Artisan and Nugget Penman
Knight of NI
Ray.R
Posts: 10,574

Re: Why some people say Local Variables are bad...

It's always amusing to see a Global going to a Local.  Maybe they get paid by the number of Global + Local useage. 
______________________________________________________________________
Kudos!!!! Gimme Kudos!!!! It's that little golden star on the left below my avatar... :smileyhappy:
Knight of NI
Ray.R
Posts: 10,574

Re: Why some people say Local Variables are bad...

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

 

 

______________________________________________________________________
Kudos!!!! Gimme Kudos!!!! It's that little golden star on the left below my avatar... :smileyhappy: