How efficient is std::string compared to null-terminated strings?

前端 未结 14 2031
心在旅途
心在旅途 2020-12-28 19:23

I\'ve discovered that std::strings are very slow compared to old-fashioned null-terminated strings, so much slow that they significantly slow down my overall pr

14条回答
  •  隐瞒了意图╮
    2020-12-28 20:06

    If used correctly, std::string is as efficient as char*, but with the added protection.

    If you are experiencing performance problems with the STL, it's likely that you are doing something wrong.

    Additionally, STL implementations are not standard across compilers. I know that SGI's STL and STLPort perform generally well.

    That said, and I am being completely serious, you could be a C++ genius and have devised code that is far more sophisticated than the STL. It's not likely , but who knows, you could be the LeBron James of C++.

提交回复
热议问题