how memory allocation happens for map and string in c++ -


i using global declaration of map<string,string> type.

  1. if execute code, strings created in dynamic memory?
  2. is map created on dynamic memory or static memory?

-

#include <iostream> #include <map> #include <string>   std::map<std::string, std::string> mymap;  class myobject { public:     myobject()     {         mymap["a"] = "astring";         mymap["b"] = "bstring";         mymap["c"] = "cstring";     } };  int main() {     myobject obj1;     std::cout << mymap["b"] << std::endl;     return 1; } 

there fixed size object representing map itself, have made global (same kind of storage static). have form of pointers dynamic memory contains variable size contents of map. includes strings in dynamic memory, other stuff (implementation dependent) in dynamic memory.


Comments