* John Doe:
Quote:
* Victor Bazarov:
>
Quote:
>Why do you care, anyway?
>
because all kinds of allocation take time and, say 10000s of stack
allocations could make an impact on execution time. It figures that it's
unspecified, but what is the rule-of-thumb? What do modern C++ compilers
usually do?
Stack allocation is mostly a conceptual device, and conceptual
operations do not necessarily take time.
A modern compiler implements the C++ automatic storage stack (LIFO
automatic allocation) by reserving a suitably large chunk of (machine)
stack space on function entry, using one or at most three instructions.
Disregarding function calls, further (machine) stack allocations do not
(typically) take place during execution of the function's code, except
if it uses extensions such as _alloca() or C99 dynamic arrays.
Initializations of local objects can still take time. However, local
variables of built-in types are by default not initialized, and anyway,
modern compilers also do such things as moving invariant code out of
loops, so as others have remarked, /measure/ before trying to optimize.
Btw., please include some mention of whom you're quoting.
I've added back the missing information above.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?