On 2009-Apr-29 12:10:44 -0700, John Gemignani <john.gemign...@isilon.com> 
wrote: 
>Are local variables allocated on-the-fly on the stack or does the
>compiler preallocate the space on entry?

This is compiler and optimisation dependent.  As a general rule, if a
compiler is not performing any optimisation, it is likely to allocate
all variables on the stack.  An obvious code optimisation is to keep
variables in registers instead of storing them on the stack.

In the specific case of older gcc versions with optimisation enabled
(I'm not sure of the behaviour of gcc 4.x), gcc will immediately spill
(allocate on the stack) local variables that aren't eligible to be
held in registers (eg too large or the variable address is taken) and
allocate remaining variables to virtual registers.  During code
generation, virtual registers are mapped to physical registers and any
remaining virtual registers are allocated on the stack.

> If I have to delve into a
>crashdump, having the variables on the big entry allocation has been
>very helpful in the past.

OTOH, not caching variables in registers has a significant adverse
impact on performance.

-- 
Peter Jeremy

Attachment: pgpK1xJipjZo7.pgp
Description: PGP signature

Reply via email to