7 ms·
I've never seen a guide, but I worked on some console games around 15 years ago where the rule was "malloc is evil". That mindset was enlightening and felt "cor
by mypalmike 7y ago
I've never seen a guide, but I worked on some console games around 15 years ago where the rule was "malloc is evil". That mindset was enlightening and felt "correct" compared to some of the sloppy memory management I'd seen (and, sadly, implemented) on some PC game titles I'd worked on before.
Basically we treated the heap like a stack of large context oriented memory blocks. Each of these blocks contains fixed data loaded from disk (static game resources like bitmaps, UI layouts, etc) and fixed size pools of fixed size game objects. The big blocks would get allocated in a stacked manner at distinct times like game title load and level load.
So if your game has bullets, you have a memory pool of say, 100 bullets to maintain the state of each instance. If you try to shoot a 101st bullet, you either don't or you have an ejection strategy. You never malloc or free during gameplay : you only allocate from one of the pools.
When it's time to unload the level... boom, you free the whole block at once, popping this stack. This is extremely efficient compared to freeing many individual malloc allocations.