Author: Daniel Clausen
Date: 11:53:29 09/03/01
Go up one level in this thread
Hi On September 02, 2001 at 07:29:12, Uri Blass wrote: >My question is when it is a good idea to define global variables >instead of local variables Ah that's an easy one: define a variable as local if it only has a local meaning, define it as global, if it has a global meaning. ;) As a rule of thumb, few variables really have a global meaning. >I found a trick to make my program slightly faster by defining them >also as global variable and not using them as local variables in part >of the cases. ... and next time you change something to the code the speed behaviour can be different because the 'layout' of your program in memory is slightly different. On a different platform it may also be completely different. (that is, if you care for other platforms ;) >Is there a way to know when it is faster without testing for every variable? Um.. what speed advantages do you get by messing up with the scope of variables? :) Are you that interested in that extra 2% speed? Call me stupid but I fail to see why anyone would want to decrease the readability of the source code that much to get a lil speed bonus. I remember a guy (on the net, not personally) coding in Java who skipped the explicit bound-check when looping thru an array, but catching the OutofBound-Exception instead... Yeah it might be slightly faster for big arrays but I would fire that guy from my company. (if I had one ;) Regards, Sargon
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.