M
Michiel Salters
....Steve said:Hi,
I'm using a std::vector to store a list of user defined objects. The vector
may have well over 1000 elements, and I'm suffering a performance hit. If I
use push_back I get a much worse perfomance than if I first define the
vector of a given size, then write to the elements with myvec =
Yup, you will on any random-access container, since it has to copy
memory. Unfortunately it'll probably do it about as fast or faster
than anything else you could write. Though I've seen dequeue perform
significantly faster than vector on the g++ compiler, for no reason I
could fathom.
deque surprises you, because it is a random-access container that does
not copy its elements. Worst case, it copies a few internal pointers.
One alternative would of course be a vector<Obj*>. Copying 1000
pointers is probably cheap enough. The disadvantage is of cource that
it requires manual memory management. Another alternative is using
a vector of (boost:
don't require the explicit management.
Regards,
Michiel Salters