# When to use an Array vs When to use a Vector, when dealing with GameObjects?

I understand that from other answers, Arrays and Vectors are the best choices. Many on SE claim that Linked Lists and Maps are bad for video game programming.

I understand that for the most part, I can use Arrays. However, I don't really understand exactly when to use Vectors over Arrays.

Why even use Vectors? Wouldn't it be best if I simply always used an Array, that way I know how much memory my game needs?

Specifically my game would only ever load a single "Map" area of tiles, such as Map[100][100], so I could very easily have an array of GameObjectContainer GameObjects[100][100], which would reserve an entire map's worth of possible gameobjects, correct?

So why use a Vector instead? Memory is quite large on modern hardware.

• Jun 25, 2013 at 20:07
• There are times you want things to be fixed sized, and there are times you want to dynamically sized. The use cases for that determines which one you'll be using. But as an aside, you should probably be using std::array for fixed-sized arrays instead of C-arrays since they're designed for similar safety that vectors are. Jun 25, 2013 at 20:15
• linked lists are fine for games - just not naively heap-allocated structures like std::list. an inline (zero-allocation overhead) linked list is great if used properly. likewise, std::map and std::unordered_map can be problematic, but a well-written tree or hash table that plays nicely with memory and cache is invaluable. be wary of any advice that claims some technique is always too slow or perfectly fast - as much truth as those claims might be founded in, there's always more details you have to consider (and measure!) for each situation. Jun 25, 2013 at 23:46