SSO enables short strings to be stored on stack. What if I have a std::map<std::string, std::string> (or any std container for that matter) which consists mainly of short strings (1 to 10 characters), and it grows to a big size (let’s say 200,000 pairs). With average length of 5, this will take up around 2 MB on characters alone, which is more than enough to cause stack overflow if SSO will work for all the strings.
So the question is: how likely is the stack overflow? How exactly SSO will work in that case (MinGW 6.0, C++14, Windows 10 x64 machine)?
>Solution :
Your notion of "stored on the stack" is wrong. The std::map allocates its elements dynamically. Whether the std::string will dynamically allocate the characters is then not that relevant anymore.
What you store on the stack is sizeof(std::map<std::string,std::string>) and that is a compile time constant. It does not change with number of elements or length of the strings.