This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: An article I alluded to
- From: Jeffrey Law <law at redhat dot com>
- To: Bill McEnaney <bill at rkirkpat dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 26 Jul 2006 22:24:49 -0600
- Subject: Re: An article I alluded to
- References: <20060727030600.EF4DF71A01@saratoga.rkirkpat.net>
- Reply-to: law at redhat dot com
On Wed, 2006-07-26 at 21:06 -0600, Bill McEnaney wrote:
> Hi, everybody,
>
> In another e-mail, I told you about an article that said that the
> computer can access static variables faster than it can access automatic
> variables. So here's a link to that article.
>
> http://www.numerix-dsp.com/appsnotes/c_coding.html
Whomever wrote it doesn't know what they're talking about, at least
not in regards to efficiency of storage access in general purpose
C compilers.
You're far better off using automatic storage for a variety of
reasons. Even when the variable can't live in a register and
thus has to live on the stack, it's generally still as efficient
or more efficient than static or heap variables. There is no
extra indirection penalty for accessing stack storage.
In addition to the efficiency concerns, auto storage is thread
safe, statics are not. auto storage doesn't require explicit
programmer management, heap storage generally does.
Most modern compilers ignore the "register" keyword, they actually
do a better job at determining what belongs in a regisrer than
most programmers.
Jeff