I would like to store a mapping of an integer
key to a float
value in-memory.
I have roughly 130 million keys (and, accordingly, 130 million v
A vector is absolutely going to kill a map here assuming you don't need to do insertions in the middle of the vector. I wrote a custom allocator to track memory usage, and here are the results in Visual Studio 2005:
std::map
1.3 million insertions
Total memory allocated: 29,859 KB
Total blocks allocated: 1,274,001
Total time: 17.5 seconds
std::vector
1.3 million insertions
Total memory allocated: 12,303 KB
Total blocks allocated: 1
Total time: 0.88 seconds
std::map is using over twice the storage and taking 20 times longer to insert all the items.