I have a 3D game where objects are stored in a 3D array. Every object is a struct of a relatively large size (a few megabytes, 4,194,304 bytes to be precise).
If I store them as an array of raw values: gameObject objects[64][64][8], they are all stored in one place, but every object is allocated, regardless of whether or not it is used.
However, if I allocate the array as an array of pointers: gameObject *objects[64][64][8], unused objects (which may be over half of the entire array) will not be allocated until they are needed, reducing the memory impact, but might be slower because the objects are all over the memory
Considering the tradeoffs between performance and memory usage, which is the best approach? Are my concerns valid?