A comparison of how many reallocations a worse case poorly coded use of realloc() does, compared to just using std::vector. 10000000 integers are added to the containers one-by-one. Clearly you would never abuse realloc() like this in real code, but it’s interesting nonetheless. Idea from sacrebleu at Freenode’s ##C++.

Sure, but then it devolves into what the “correct” growth factor is and whether you should use custom code or just trust the stdlib. The various C++ stdlibs grow std::vector at a pace that fits 99% of use cases.

This really was just a silly “what if the coder was a moron” test, which realloc() naturally loses. Except on OS X, which is in the same order of magnitude.