Jeffrey Law schrieb:
I guess there _are_ machines/environments where static allocation is
better, because I've run across programs where they quite annoyingly
declare just about every (semantically) "local" variable as static.
Certainly on some specialized processors accessing memory can be
fast. Consider a processor where registers are really just aliases
for memory locations or things like high speed zero page memory access.
I've used such processors a few times in my life, but I try real hard
to forget them ;-)
Well, it may be not just about speed. On small embedded systems, for
instance, it is often required to be as thrifty as possible with the stack.
Therefore embedded system developers tend to prefer global (static) over
local (auto) variables, which may include even passing parameters via
globals (if they can't be passed in registers).
Generally, in this domain, memory, especially RAM, is a much more limited
resource than CPU cycles. A smart linker can organize static variables
optimal among the available memories. Furthermore, if they don't fit into
the available memory this is reported at link time. For the stack(s) it is
a lot more complicated to calculate the required size.
Daniel