I've heard many people say that if the number of expected elements in the container is relatively small, it is better to use std::vector
instead of std::map
even if you were to use the container for lookups only and not iterating.
What is the real reason behind this?
Obviously the lookup performance of std::map
cannot be worse than std::vector
(although it may differ in nanoseconds/microseconds) so does it have something to do with memory usage?
Does std::vector
fare any better/worse than std::map
in fragmenting the virtual address space?
I am using the STL library that comes along with Visual Studio (i.e. Microsoft's implementation). Does that make any difference compared to other implementations?
See Question&Answers more detail:os