Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: question about local and global variables

Author: Olaf Jenkner

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

Go up one level in this thread



>I don't see why local variables would be faster or slower than global
>variables.  Locals are accessed as offsets from a fixed point in the
>stack.  Globals are accessed directly.  I don't see any real reason
>why one would be faster than the other.  More likely it is an issue of
>locality.  Variables that are used close together in time should be
>stored close together in memory to take advantage of the way a cache
>line fill sucks in thirty-two consecutive bytes in memory...
>
>That can pre-fetch important data if it is stored in the correct order
>in memory.
>
>
I have a program written in Delphi. After removing global variables and using
them local the code was shrinking significantly. That's why an access can be
done shortly with a small offset of the stack pointer. To use global variables
you have to give 4 bytes that represent the position in memory.
That means, also the instructions stay better in cache.

OJe



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.