What is better, a STL list or a STL Map for 20 entries, considering order of insertion is as importa
Posted
by Abhijeet
on Stack Overflow
See other posts from Stack Overflow
or by Abhijeet
Published on 2010-04-12T06:18:15Z
Indexed on
2010/04/12
6:23 UTC
Read the original article
Hit count: 391
I have the following scenario.The implementation is required for a real time application.
1)I need to store at max 20 entries in a container(STL Map, STL List etc). 2)If a new entry comes and 20 entries are already present i have to overwrite the oldest entry with the new entry.
Considering point 2, i feel if the container is full (Max 20 entries) 'list' is the best bet as i can always remove the first entry in the list and add the new one at last (push_back). However, search won't be as efficient.
For only 20 entries, does it really make a big difference in terms of searching efficiency if i use a list in place of a map?
Also considering the cost of insertion in map i feel i should go for a list?
Could you please tell what is a better bet for me ?
© Stack Overflow or respective owner