David Brown wrote:
> On Mon, Jan 07, 2008 at 02:59:52AM -0800, Andrew Lentvorski wrote:
>
>> It is considered bad style in C++ because of the semantics of stack
>> allocation.
>>
>> Declaring everything at the top of a function means that everything
>> gets allocated on the stack immediately upon function entry and is
>> held until function exit.
>
> I doubt you could find a compiler still around that would perform this
> basic of an optimization.  I'm not even sure you would ever find a
> compiler
> that accepted mixed-declarations and allocated by default on exit.  The
> only time you need to delay the allocation is when the size isn't known
> until the declaration (such as an array dimension).  In this case, it
> wouldn't be possible to move the declaration to the top anyway.
I think Andrew was probably referring to initialization (which can be
insanely expensive) more than allocation, but even in the case of
allocation it can end up making a not insignificant difference.

--Chris

-- 
KPLUG-LPSG@kernel-panic.org
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to