"xarax" <xa***@email.com> writes:
[snip]
Peng Jian wrote:
> I have a function that is called very very often.
> Can I improve its efficiency by declaring its local variables to be
> static?
[snip] It's entirely implementation dependent. Therefore,
the answer is no.
It's entirely implementation dependent. Therefore, the answer is that
it's entirely implementation dependent.
If the OP had asked whether he can *portably* improve efficiency by
using static variables, the answer would be no.
It's within the realm of possibility that making a function's local
variables static could improve performance on a particular system in a
particular set of circumstances. (It's also entirely possible that it
could degrade performance.)
But to answer another question that the OP didn't ask but probably
should have:
Is it a good idea?
Probably not, unless you've already tried everything else, and you're
desperate to shave a few more cycles off your run time, and you've
actually measured the performance increase, and you're going to modify
the source in a way that makes it easy to go back to local variables
when your optimization becomes a pessimization on the next system you
port the code to, and you actually have the patience to read this
absurdly run-on sentence (which I suppose is really a run-on sentence
fragment, but I digress).
(Shorter answer: No.)
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.