jeudi 2 mars 2017

Does unordered map frees its memory after calling clear?

I know that unordered map removes the objects that were stored in it when doing clear() but does it also relinquishes the memory that it hold to create itself.

struct A{
   A(){std::cout << "constructor called\n";}

   ~A(){std::cout << "destructor called\n";}
};

// this will reserve size of 1000 buckets
std::unordered_map<int, A> my_map{1000};
     my_map[1] = "asdf";
     my_map[2] = "asdff";
     ....

then I do my_map.clear(); This will call destructor of A.

So my question is will the 1000 buckets that was reserved also be freed? I tried looking at the size() after doing clear it says zero or is there something like capacity for unordered_map that is similar to vector?

Aucun commentaire:

Enregistrer un commentaire