c++ - Avoid malloc() when doing unordered_map -


try use has map in c++. problem when add constant entry mymap["u.s."] = "washington";, used malloc() (i verified when using gdb breakpoint on malloc()). unnecessary calls malloc reduce performance, hence trying avoid as possible. ideas?

#include <iostream> #include <unordered_map>  int main () {   std::unordered_map<std::string,std::string> mymap;   mymap["u.s."] = "washington";   std::cout << mymap["u.s."] << std::endl;    return 0; } 

i know malloc necessary when scope of key short, since 1 may need use mymap[key] after key destroyed. in case, keys (a huge number of them) persisitent in memory .


Comments

Popular posts from this blog

Java 8 + Maven Javadoc plugin: Error fetching URL -

android - How to delete or change the searchview icon inside the SearchView actionBar? -

c++ - Msgpack packing bools bug -