Quote:Original post by Adam Hamilton
I am a bit confused. Shouldn't the non dynamically allocated vector be allocated once while the dynamically allocated vector be allocated 100000 times.
No - the for loop creates a scope, which is reconstructed every loop.
for ( unsigned i = 0 ; i < 3 ; ++i ) { ThisClassSaysHelloInItsConstructor example;}//End result: Hello printed 3 times.
While each version would typically stay in the same place, with a non-POD type like std::vector, the (de)constructors still need to be called.
Quote:Original post by Boder
Quote:Original post by penwan
Just a quick note for those interested:
In the latest STL implementation by MS in VC++ 2005, bounds checking is done even in release builds by default. To disable this behavior, you must #define _SCL_SECURE to be 0 before including any STL headers.
I don't know what to say to this.
One one hand, it seems like a wonderful idea, fixing bugs made by programmers. Enabling it by default for progammers too lazy to consult their documentation to enable it seems like a good idea.
On the other hand, this is a clear violation of the zero-overhead rule with which C++ was designed (you don't pay for what you don't explicitly use - which should be at() for runtime bounds checking, explicitly made for this purpouse), and is a horrible mistake to enable by default - such tricks could lead to a lower adoption of the STL in the first place, creating more bugs (as standard containers are repeatedly clone-developed) than it solves in the first place.