Chinji
Chinji

Reputation: 41

Move semantics and string performance

I read somewhere that the new standard force move semantics in the implementation of the string class. Right now compilers like gcc for example, implement the strings as copy on write to improve performance, this makes copying and passing string as parameters by value very cheap. Now if move semantics for copying strings are now mandatory, isnt that a performance lose?. Because if it is true that it will be cheap to pass strings moving them between scopes it will still need to do the copy if/when you copy the string, right?.

Can someone clarify this issue for me?

Thanks.

Upvotes: 4

Views: 292

Answers (1)

Xiangyan Sun
Xiangyan Sun

Reputation: 453

Why you're counting move semantic a loss of performance? When it's correctly implemented, move a string is equivalent to copy several pointers only.

Well, for raw copying COWs are good, but they're bad for a multi-threaded environment and people're seeking ways to disable it.

http://www.gotw.ca/gotw/045.htm

Turning off COW in GCC

Is std::string refcounted in GCC 4.x / C++11?

At last, most string operations in a practical program are just passing it to other functions as is, so a const & is enough for performance.

Upvotes: 5

Related Questions