Big vector accessed by different classes

What's the most sensible way in regards to performance?

I have a large vector of objects and different classes that need to access it.
The app is something like a game, there's a central update() method running 60 times a second, that calls the other classes' update() methods.
In each call the classes will need to access the vector.


A) Pass a reference on each call, i.e.:
void SomeClass::update( vector<MyItems> & items );

B) Each class stores a pointer to the vector, passed initially, i.e.:
void SomeClass::init( vector<MyItems> * items );

C) The vector is public so each class could access it directly


Any gotchas involved in dealing with big vectors like this?


Thanks!
There will be no difference between A and B. In both casses, the compiler pushes an address on to the stack.

C will avoid the push of the address onto the stack, but this is a poor design tradeoff. Use of globals should be avoided. 60 accesses (x # of update functions) is not worth worrying about the performance.

Of more concern is how many items are in the vector and how many are actually being updated. i.e. Is each update function scanning a large nunmber items in the vector and only updating a few? If so, this is where your inefficiency is.
Last edited on
Thanks! Makes sense. :)
Topic archived. No new replies allowed.