Is it OK, performance-wise, to return a string
from an arbitrary function in C++11? What is the preferred way of returning a string if "directly returning" it is not recommended?
AFAIK, strings in C++ are not reference-counted because the standard forbids this practice. From my (probably uninformed) point of view, this means that a string will be returned by copy-constructor, resulting in a possibly large memcpy
. Is this right?
It is very straightforward and clean to define a function as string MyClass::makeString(...)
instead of something like void MyClass::makeString(string & ret, ...)
. On the other hand, the latter approach might seem better from a performance perspective.