C++: map and hash_map performance
Posted on 2008-11-07
Hi, a general question on map and hash_map:
I am doing a performance enhancement on a program; the program processes a data file every 5 minutes.
Initially the program used the STL map to store the (key, data) pair. But it seems like it slows down after a while (about one day) then picks up the speed after a period of time (after several hours).
Then the hash_map is used since the the hash_map can find the key faster. But then the same behavior happens on the new implementation of using a hash_map.
So now the quesiton is: does this kind of behavior have somehting to do with the memory allocation? The program (map or hash_map) takes a data file, read the content to set the key and its value; but at some point of time the map or hash_map erases the pair once the key/data is no longer needed.
The only cause I can come out with is that: the allocation of memory is done for evvery new data pair, then when this data pair is erased from the map/hash_map, the memory is not released for a period of time (a lot of (key, data) pairs are added and removed from time to time) so the new memory allocation of new pairs takes a long time (to find a good memory location). At some point of time, the OS comes in to reclaim the memory (from the deleted data pairs) so the process can run fast again.
Not sure this is exactly what happened; so experts please offer your comments on how/what I should do to improve the performance.