• Advertisement
Sign in to follow this  

Efficiently Handling a Large amount of Objects with Short Lifespans

This topic is 1397 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

 

 

 

 

 

Share this post


Link to post
Share on other sites
Advertisement

Yes, it seems that pool allocation definitely fits the criteria. I'll look into it.Thanks for the information.

 

Any other suggestions are welcome.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement