P
Papadopoulos Giannis
a) pre vs post increment/decrement
I have read somewhere that:
“Prefer pre-increment and -decrement to postfix operators. Postfix
operators (i++) copy the existing value to a temporary object, increment
the internal value, and then return the temporary. Prefix operators
(++i) increment the value and return a reference to it. With objects
such as iterators, creating temporary copies is expensive compared to
built-in ints.”
A modern compiler wouldn’t make the optimization, so
i++;
and
++i;
would give the same instructions?
b) I find that realloc() calls sometimes take more time to complete than
malloc() calls. Is this the general case?
c) Why do some people declare all the variables at the start of each
function? And I mean ALL variables, including those that are nested in
deep fors and ifs... I don’t see any obvious performance gains - unless
they do it to remember what they are using...
I have read somewhere that:
“Prefer pre-increment and -decrement to postfix operators. Postfix
operators (i++) copy the existing value to a temporary object, increment
the internal value, and then return the temporary. Prefix operators
(++i) increment the value and return a reference to it. With objects
such as iterators, creating temporary copies is expensive compared to
built-in ints.”
A modern compiler wouldn’t make the optimization, so
i++;
and
++i;
would give the same instructions?
b) I find that realloc() calls sometimes take more time to complete than
malloc() calls. Is this the general case?
c) Why do some people declare all the variables at the start of each
function? And I mean ALL variables, including those that are nested in
deep fors and ifs... I don’t see any obvious performance gains - unless
they do it to remember what they are using...