quote:
Then the memory allocation is exactly the same for both versions, however, the first code will take performance hit for the construction multiple times, am I right?
Yes.
quote:
Build in type has no construction costs? if I have a blank constructor for my class is it considered to have no construction costs?
Yes, but I believe it has to be inlined. Might depend on the compiler. If your constructor is defined like this in the header:
myClass::myClass () { }
..then I believe there is no construction costs. Something you should check the assembly listing for, though.
Note to AP: You''re correct. I wanted an unoptimized compile so you could see what was happening line-for-line. Also, I wanted to show that this is not an optimization feature, but a language feature.
Note to Gladiator: Other reasons your argument doesn''t work:
- there''s no way to differentiate between each of the new ''s'' arrays each time in the loop. If the first s is at BP-0, where''s the next one? And the next? How are they described as different symbols at compile-time?
- moving the stack pointer after you''ve updated the base pointer will mean you loose everything you''ve pushed. When you pop, you''re popping from a different stack location.