Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Question about static vs global variables

Author: Matthias Gemuh

Date: 05:34:11 10/27/01

Go up one level in this thread


On October 27, 2001 at 06:58:49, Gareth McCaughan wrote:

>Frank Phillips wrote:
>
>> Are there any issues associated with time?  Presumably at runtime
>> storage has to be created for local variables in a recursive function,
>> such as ABSearch(), and then destroyed; whereas it has to be created
>> only at initialisation for globals.
>
>No, it's basically free. A recursive function call
>(actually, almost any function call) will involve
>making some space on the stack to store things; local
>variables just get some space there. The only "creation"
>needed is adding a slightly larger number to the stack
>pointer. <pedant>Which, I suppose, may mean a very
>slightly larger number of page faults and slightly
>worse cache performance, but so will the extra space
>needed by globals *all* the time.</pedant>


This logic doesn't look sound to me. Every recursion has to allocate (and later
free) space for local (non-static) variables. Each recursion DOES NOT reallocate
memory for global variables, so there should be a perfomance issue.

Regards,
Matthias.







>
>You don't avoid the overhead of creating a stack frame
>(i.e., that space on the stack for storing things) even
>if your function uses no local variables, by the way.
>There will still be things that need to be stored.
><pedant>Unless your function is simple enough that
>the compiler can inline it, or something like that.</pedant>
>
>--
>g



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.