I am migrating an old code base from using a custom implementation of strings to use std::string. One of our engineers is concerned that this could lead to a performance issue where we are using += and + to concatenate relatively long strings. His particular concern is how the memory is allocated as the string grows dynamically, and he suggested that stringstream would perform better in this regard. For those of you tempted to respond "benchmark then optimize" or sentiments to those effect -- I do of course agree, and that's the plan. I'm just wondering about the theory.
I did a little searching for this issue, and ran into this question: Efficient string concatenation in C++, which is getting a little dated.
Now I'm wondering: Is the memory allocation algorithm for string += really different than that for string stream? What about the copy issues raised in the above question -- have these changed with c++ 11/14?