Standard container re-allocation multipliers across popular toolchains

Dinkumware STL (shipped with Visual Studio) uses a 1.5 multiplier, Gcc uses 2. I cannot really tell for the rest, but I think those are the most often used numbers. (IIRC, I read once that most implementations used 2)

As a side comment, you are correctly calling it a multiplier since the standard requires the growth to be (at least) geometrical.


New answer for an old question.

Rationale: The answer can be answered programatically, and with online compilers, relatively easily. Here is a program that can help you answer this question:

#include <climits>
#include <cstddef>
#include <cstdlib>
#ifndef _MSC_VER
#   include <cxxabi.h>
#endif
#include <iostream>
#include <memory>
#include <string>
#include <typeinfo>
#include <type_traits>
#include <limits>
#include <vector>
#include <string>

template <typename T>
std::string
type_name()
{
    typedef typename std::remove_reference<T>::type TR;
    std::unique_ptr<char, void(*)(void*)> own
           (
#ifndef _MSC_VER
                abi::__cxa_demangle(typeid(TR).name(), nullptr,
                                           nullptr, nullptr),
#else
                nullptr,
#endif
                std::free
           );
    std::string r = own != nullptr ? own.get() : typeid(TR).name();
    if (std::is_const<TR>::value)
        r += " const";
    if (std::is_volatile<TR>::value)
        r += " volatile";
    if (std::is_lvalue_reference<T>::value)
        r += "&";
    else if (std::is_rvalue_reference<T>::value)
        r += "&&";
    return r;
}

template <class C>
void
test()
{
    C c;
    std::cout << type_name<C>() << ":\n";
    std::size_t c0 = c.capacity();
    std::cout << "    Initial capacity is " << c0 << '\n';
    c.resize(c0);
    for (int i = 0; i < 10; ++i)
    {
        c.push_back(typename C::value_type{});
        std::size_t c1 = c.capacity();
        if (c0 != 0)
        {
            float f = static_cast<float>(c1)/c0;
            std::cout << "    growth factor appears to be " << f << '\n';
        }
        c0 = c1;
        c.resize(c0);
    }
}

int
main()
{
    test<std::vector<int>>();
    test<std::string>();
}

Most of the complexity is a bit unnecessary as it is just to get type_name working.

libstdc++:

http://melpon.org/wandbox/permlink/njaIG2uiR2vlCLZz

appears to answer a solid 2 for both vector and string.

VS:

http://webcompiler.cloudapp.net

is very close to 1.5 for both vector and string.

libc++

http://melpon.org/wandbox/permlink/mXshrLJHgNuvE1mD

is very close to 2 for both vector and string.

Note that this program also tells you what the short string buffer is for string: 15 for both libstdc++ and VS, and 22 for libc++.