No matter what fancy allocator you come up with, memory allocation will always be expensive. In order to reduce memory allocations I have been using stack-allocated containers for the past four-five years and I think it has worked really well, so I thought I'd write a post about them here. These methods have been used in all our games (Sprinkle, Granny Smith, Smash Hit as well as our new project). Using containers is really convenient and often necessary. Take the array for example: MyArray<Object> array; Everybody's got one. The problem with these are that you need to allocate memory when putting stuff in them. In many cases you know on beforehand approximately how many objects you want to put in there, reducing it to a single allocation: MyArray<Object> array; array.reserve(50); But if this code is in a function that is called frequently it would be much nicer if those first fifty objects were reserved on the stack instead of the heap, like this: My
A game technology blog with focus on physics. I'm the co-creator of mobile games Smash Hit, PinOut, Does not Commute, Granny Smith, Beyondium and Sprinkle. Twitter handle: @tuxedolabs