Thread: Extensible vector in both ends?

  1. #16
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    3) Don't really erase elements. Instead, mark them as erased. Re-use the storage by searching for an erased bullet first. Because of the way aging of bullets work, keep the index of the last insertion and start your search from there; you'll get amortized constant time insertions despite the linear search for a free space, while making erasures constant-time, too.
    This is some excellent advice that has gained me numerous cycles and frames time and time again. As long as you keep track of the last bullet erased and then use that index on the next allocation you can really get some huge speed gains. You are essentially using each index in the vector as a 'slot' for 1 bullet.

    If you reserve space beforehand in the vector and use the methods that CornedBee suggests you will hardly ever need to use a list. I've found lists to be quite slow and rather limiting when it comes to containers. I'm not saying they are worthless but I rarely use them unless the situation warrants it (like my cache resource manager).
    Last edited by VirtualAce; 10-04-2007 at 11:33 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extensible language... What?
    By jordanguyoflove in forum C Programming
    Replies: 2
    Last Post: 10-15-2008, 10:02 AM
  2. How to cap the gluCylinder() ends
    By ting in forum Game Programming
    Replies: 1
    Last Post: 06-02-2008, 05:03 PM
  3. program ends immediately
    By willc0de4food in forum Windows Programming
    Replies: 11
    Last Post: 09-04-2005, 06:52 PM
  4. Socket abruptly closes after function ends
    By Sfpiano in forum Networking/Device Communication
    Replies: 1
    Last Post: 08-08-2005, 04:49 PM
  5. Some loose ends
    By pdstatha in forum C Programming
    Replies: 7
    Last Post: 03-31-2002, 04:03 PM