std::vector question

Started by
2 comments, last by DevFred 14 years, 6 months ago
Hi is it considerd bad practice or bad for performance to have individual vectors for lot´s of different objects. For instance all enemies in one and bullets in another. I would think it´s better to have them all collected in one additional vector for say gameobjects and iterate through that to update than to iterate each smaller vector seperatly?
Casual game dev www.apgames.se
Advertisement
Use the design that makes your code easier to understand. If you put everything inside one vector, displaying your entities is easier. If you put different kinds of entities in different containers, things like collision detection get a lot easier. Personally, I would prefer the "multiple-vectors" approach.
Agreed multiple vectors makes it a lot clearer. But is it faster to have an extra vector for updating and the specific vectors for collision etc?
Casual game dev www.apgames.se
When you iterate over a vector of entities, the actual processing of the entities is going to be somewhere around 1000x slower than the iteration itself. There is simply no point in trying to optimize the iteration. One-vector vs. multiple vectors is not a question of performance.

This topic is closed to new replies.

Advertisement