I'm having a little trouble understanding the concept of preallocating a block of memory, and only ever using that block for the game. It makes a lot of sense to me why you would do such a thing, but there are some details that I don't understand.
I'm fairly new to C, so here's my understanding of this method:
1. We allocate a block of memory (basically no layout info, so void* pointer of some size)
2. We pass a pointer to the block to the game loop, and the game loop casts the block to the layout/struct it expects: that way it can divide the memory into useful chunks as defined by the struct.
3. The platform code only knows the info as a block of memory, so I can freely change the game struct, and it won't break anything.
Here's the confusion:
When I want to add some info to the memory like player position or something, I can simply add:
1 2 3 4 | struct game_memory { float player_x; float player_y; } |
But how do I add dynamic stuff like number of vertices that are loaded from an obj file? Only way I can see right now is defining a big array, and use only the parts I need:
1 2 3 4 | struct transient_memory { vertex vertices[1000]; int vertices_count; } |
and that way I can use the vertices_count as a "watermark", and clear it to zero if I don't need the vertices later.
Other resources out there solve the problem by using std::vector, which doesn't seem like a good idea to me.
So is there a better way to do this? Or is it fine as I described it?