Myndale wrote:You actually have a number of options here. The best plan is probably to design your architecture so that you never have to do any per-frame allocations (e.g. by maintaining a bank of objects) but if that's not an option then one workaround is to declare your own form of the placement new operator like this:
I'll probably do a bank of objects. Different objects will have a different byte size in memory (because they might use different variables), so I'll either have to normalize the sizes, or maybe use unions or structs? For example, give the base enemy class an extra 32 byte struct, and have each inheriting class override that struct with any combination of variables they need that come in under 32 bytes. That way all enemies have the same size and I can allocate an array for a max number of them at compile time.
(...you can cast/override unions or structs like that, right?)
EDIT: There seem to be a few solutions
here that will help me out.