array vs vector vs list
Solution 1:
Use STL vector
. It provides an equally rich interface as list
and removes the pain of managing memory that arrays require.
You will have to try very hard to expose the performance cost of operator[]
- it usually gets inlined.
I do not have any number to give you, but I remember reading performance analysis that described how vector<int>
was faster than list<int>
even for inserts and deletes (under a certain size of course). The truth of the matter is that these processors we use are very fast - and if your vector fits in L2 cache, then it's going to go really really fast. Lists on the other hand have to manage heap objects that will kill your L2.
Solution 2:
Premature optimization is the root of all evil.
Based on your post, I'd say there's no reason to make your choice of data structure here a performance based one. Pick whatever is most convenient and return to change it if and only if performance testing demonstrates it's a problem.