array vs vector vs list

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.

Leave a Comment