I recently read this answer on this site, which says the following:
making sure no allocation/deallocation is being done while the game is running is a golden rule of thumb.
I interpret this as meaning that you should do all the necessary heap allocation while the game is booting up, and arrange it in object pools that you then manage when the game is running. Is this statement correct? The reason I'm struggling to understand it is because I thought that that goes against one of the main reasons we use dynamic heap allocation in games.
That I know of, there are three main uses for using dynamic allocation on the heap:
- You have data whose size cannot be know at compile time and needs to be dynamically allocated at runtime.
- You need to store objects that take up a large amount of space and won't fit on the stack
- You have data whose lifetime outlives the current scope and thus must be stored on the heap.
I was under the impression that one of the main reasons for heap storage being used in games was reason 1, that you can't know the size of data collections beforehand and therefore need to work with dynamic memory. But if all the heap data should be allocated while the game is booting up, then that can't be true.
So does this mean that the reason we use heap storage in games is actually just reason 2 and 3?