This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: An article I alluded to


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]