3 ms·
"There can be a lot of projectiles, they appear and disappear quickly, and every time that happens we incur the cost of allocating/deallocating memory multiple
by failrate 12y ago
"There can be a lot of projectiles, they appear and disappear quickly, and every time that happens we incur the cost of allocating/deallocating memory multiple times."
I write a lot of shoot-em-ups (both 2d and 3d). I never do this. I preallocate all of the bullet entities on level initialization and never destruct them during runtime. If the number is large enough, I do sort them by status (alive or dead) and exit processing when I encounter a dead projectile, but usually that's unnecessary.
- enjoy-your-stay 12y agoDo you pre-allocate all bullets per shooter? Or have one big bucket that all shooters use? I take it that having a finite number of bullets in the game at any time is obviously an acceptable trade-off.