C++: map and hash_map performance

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.

Who is Participating?
cw1592Author Commented:
some testing shows that the allocation of the value in the pair of (key, value) has the key impact on the performacne; using a memory/data allocation call from the Boost library can be used to improve the perfromace of the STL map.
Use a code profiler to look at performance and easily identify exactly areas could be improved.  Red-gate ants would be an example.
cw1592Author Commented:
BTW, the program is running on a Linux box.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.