This topic is now archived and is closed to further replies.


How to use std::list ... good for mass amounts of bullets ?

Recommended Posts

Guest Anonymous Poster   
Guest Anonymous Poster
You use push_back to put the bullets in the list and erase them as they hit enemies or walls. Really, what do you want to know? std::list is not a command, it''s a class.. You need to grasp that concept pretty well if you want to do anything.

Though using std::vector is probably a better choice. As long as you''ve used reserve() to allocate enough memory, push_back in vector is very fast, iterating it will also be probably be a bit faster and it''s more intact in memory (good for cache). Removing a bullet from vector can be done fast by swapping the eraseable bullet with the last bullet in the vector and then shrinking the vector''s size by 1. That won''t preserve the order of bullets in the list, but often that''s not useful.

Share this post

Link to post
Share on other sites