Concatenating text strings is a common task, but generally an expensive one because it involves dynamic (heap) memory allocation, copying, and deallocation. For instance, consider an example where a series of STL string objects hold fragments of text that need to be joined together and returned from a function. This perfectly legal implementation generates the result that is required, but what of its efficiency? To understand the performance of this, look at how the return expression is evaluated.
展开▼