Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: question about local and global variables

Author: Dieter Buerssner

Date: 10:00:35 09/03/01

Go up one level in this thread


On September 02, 2001 at 21:45:28, Robert Hyatt wrote:

>I don't see why local variables would be faster or slower than global
>variables.

I have mentioned one reason in another post. Another reason is, that accessing
global variable needs in general longer code (not necessarily mor instructions)
on the x86 architecture.

Compare for example

  mov [ebp-4], 2 ; typical access to local variable via frame pointer

to

  mov [_global_var], 2

If I remember correctly, the later will use 2 bytes more.

Of course, when the compiler can (temporarily) allocate a register for a
important var, this will need even less code and time in general.

Often having a local copy of a much used global var can speed up code
significantly.

Dieter




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.