Author: Tom Kerrigan
Date: 14:05:06 10/26/01
Go up one level in this thread
On October 26, 2001 at 16:56:19, Derek Mauro wrote: >As far as I can tell, static and global variables seem to be equally efficient, >the only difference being that statics have a limited scope. Am I right, or is >one actually more efficient than the other? Is there any advantage to passing >around a static or a global? I've always read that globals should be avoided. >Is there any performance reason why? > >Thanks for your help in advance. I assume you mean static -> local. (?) In the olden days, local vars were allocated on the stack (usually fast) and globals were in the heap somewhere, possibly other segments (very slow). Registers were also not allocated for globals (extra slow). These days, it doesn't really matter where your variables are located in memory (caches are great!) and registers are allocated for anything. So it shouldn't make a difference. Realize that there may be overhead for passing variables between functions; most compilers can do fast calls, where arguments are put in registers instead of the stack, so this is often a wash, too. Basically, program in the way that seems the most straightforward to you and it's a safe bet that it will be fast. No harm in trying things multiple ways, though, of course. :) -Tom
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.