Passing by value for a C++ non-trivial class involves invoking the copy constructor, so the decision, performance-wise, depends from what it does.
If we are talking about MFC/ATL CString
, its copy constructor doesn't perform a deep copy like std::string
(which may indeed be quite costly to copy, as, in the general case, it requires a new allocation and the copy of the full content), as it implements "copy on write" optimization - copies of a given CString
actually share the backing buffer until one of them tries to modify it, thus triggering the actual copy. For this reason, copies are relatively cheap, but they still involve some atomic integer fiddling, which may be not completely free on modern processors.
So: most probably a const
reference is going to be slightly faster to pass (even though access to actual data inside the function is going to suffer slightly due to an extra indirection step), but that's not anything I'd really worry about unless profiling does show it to be a bottleneck.