| re: STL Map of Pointers vs Map Containing the Data
The pointer approach will add an extra 4 or 8 bytes for each record of the data. This is an increase of either 6% or 12% to your program data size. You also have the extra work of newing and deleting the data.
Storing the data internally is fine except for modifications to the data. In this case you must copy the data to and from the map. At 65 bytes, its not too bad, but that is 8 or 16 times longer than copying a pointer.
Which is best? I don't see any clear winner here.
As for using an STL map, that's pretty much a given from your description. When you say key, element, and infer random access; that defines a map. My only caution is that maps can get slow when they get big, especially with insertions. Watch the creation of the map and see if it slows down with more and more additions. When insertions start to slow down, it only gets worst. It looks like you have a million entries and that could cause problems. Big, sloooowwww problems.
If you need other structures, then a vector will work. Concatenate the key with the data, insert at the end, and sort on the key value. This allows you to search sequentially and also do a binary search on the key. I believe the STL has algorithms that will sort and search for you.
|