You may not believe it, but vector (and better still deque ) are the fastest containers that STL can offer for most tasks.
You may worry about copying your object, but if it is not extremely huge or the Copy Constructor is a little complicated, it will cost less to copy the object that allocates it to the heap.
Heap allocation and omissions in the result cache are much larger than a simple copy.
But let's not chat in standby mode: compare your container with vector and see what is in the top, and at what level of magnitude, I'm sure you will be surprised.
And if your class is really huge or forbidden to copy, there is always boost::ptr_vector , although if you do not use the pool, you obviously throw the cache in the window;)
source share