I have searched this topic a number of times, but could not find satisfactory answers. My question is, what are some good ways to efficiently handle a large amount of objects with short lifespans in C++? (think bullets, spells, massive amounts of enemies that appear and disappear off screen) More specifically, what kind of container should store these objects? Should these objects be dynamically allocated and deallocated with "new" and "delete", thus making this a container of pointers to the objects? Instead of deleting objects directly from the list at the end of the objects' lifespan, should they be flagged as "dead" and be removed or replaced at a more opportune time?
I know that when using a vector there is a trick of swapping the element to be deleted with the very last element of the vector, then using pop_back to delete it, thus avoiding relocation of elements in the vector. What are some other tricks when dealing with a large number of short-lived objects?
The container these objects are stored in will double as a way of iterating through these objects for the purpose of updating logic, so iteration needs to be quick as well.