Memory Allocation in STL C++ -


i little confused memory reallocation in stl c++. example, know if declare vector, , keep pushing elements it, vector @ point need reallocation of memory space , copy existing elements it. linked lists no reallocation needed, because elements not stored consecutively in stack , each element uses pointer point next element.

my question is, what's situation other stl in c++ ? example, string, map,unordered_map? need reallocation ?

(disclaimer: concrete data structures specified here may not required standard, useful remember link rules concrete)

std::string ~= std::vector; it's dynamic array, if keep pushing elements @ end, @ time reallocate elements.

std::list: each element new linked list node, no reallocation ever takes place, wherever may insert new element.

std::deque: it's typically made of several pages of elements; when page full, new 1 allocated , added list of pages; reason, no reallocation of elements ever takes place, , elements never moved if keep pushing stuff @ beginning or @ end.

std::map/std::multimap/std::set/std::multiset: typically binary tree, each element allocated on own; no reallocations ever performed.

std::unordered_map/std::unordered_multimap/std::unordered_set/std::unordered_multiset: hash table; when table full enough, rehashing , reallocation occurs.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -