It looks like your free store is populated with zeros, but not your call stack. C ++, of course, does no zero initialization here, and it has nothing to do with containers.
I believe that you will see the same if you try:
#include <iostream> #include <vector> struct Foo { Foo() {} // n isn't initialized int n; }; int main() { Foo foo; // arbitrary values std::cout << foo.n << '\n'; Foo* p = new Foo; // zero values std::cout << p->n << '\n'; delete p; }
(Unfortunately, ideone.com does not demonstrate the behavior for an auto-storage variable, which is a shame. Something may be related to a locked environment in which g++ is called for fragments. However, I want to show my tricky use of #pragma !)
There is no C ++ way to manage this, and there is no way to manage Windows or Linux as far as I know.
By the way, everything that led you to this requirement is a good example of why you should not rely on uninitialization.
source share