NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Knight of NI
Knight of NI
Ben
Posts: 16,091
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

Knight of NI
Ray.R
Posts: 10,171
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
.
(starting to) See Life in a brand new way...

b* ^ )
Knight of NI
Ray.R
Posts: 10,171

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

[ Edited ]

... there's more...

 

 

Message Edited by JoeLabView on 10-09-2008 09:09 AM
.
(starting to) See Life in a brand new way...

b* ^ )
Knight of NI
Ray.R
Posts: 10,171

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.. 

 

.
(starting to) See Life in a brand new way...

b* ^ )
Active Participant
yenknip
Posts: 492
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: 492

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: 2,283
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

RFC 2323 FHE-Compliant
Trusted Enthusiast
Darren
Posts: 2,614

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,171

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. 
.
(starting to) See Life in a brand new way...

b* ^ )
Knight of NI
Ray.R
Posts: 10,171

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

 

 

.
(starting to) See Life in a brand new way...

b* ^ )
By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page