I would like to know if the STL map in c++ has contiguous memory – or is the memory assigned to the heap?
I would like to know if the STL map in c++ has contiguous memory
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since
mapis a dynamic container, the memory for its elements is dynamically allocated (whatever that means (it depends on a configurable allocator)!).Moreover,
mapis a node-based container, so each element goes into a distinct, separate allocation (so as to permit maximal iterator and reference non-invalidation). Elements are almost certainly not contiguous in memory, and probably scattered about in a way that reflects how you added them.Practically, a map will be implemented as some type of balanced tree in order to achieve logarithmic lookup, insertion and deletion times.
(If you want a data structure with contiguous storage and logarithmic lookup time, consider a sorted vector.)