C++ map vs map performance (I know, “again?”)

前端 未结 6 1955
北恋
北恋 2020-12-24 11:05

I was using a map with a std::string key and while everything was working fine I wasn\'t getting the performance I expected. I searched for places to optimize

6条回答
  •  难免孤独
    2020-12-24 11:39

    Store the std::string as a pointer and then you lose the copy constructor overhead.

    But after you have to remember to handle the deletes.

    The reason std::string is slow is that is constructs itself. Calls the copy constructor, and then at the end calls delete. If you create the string on the heap you lose the copy construction.

提交回复
热议问题