<vector> and <list>
Posted: Sat Jun 06, 2009 2:21 pm
So, I've been learning from the Lazy Foo' SDL tutorials and websites like cprogramming.com, I have pretty much read everything I can on both websites (Although there is so much information it hasn't all stuck with me yet) and have started to experiment with the new and delete keywords to create things during run-time of a program.
So far I have been making a 'Zelda: A link to the past' rip off, and have been creating new Gaurd Sprites whenever you press the 'n' key, all of them would be deleted from memory when the program is closed.
But I started to wonder if it really matters whether I use a 'list' or 'vector' to store these new sprites?
On cprogramming.com it says:
So far I have only used a list to store these new sprites, but is there really much difference as to which one to use when it comes to games?
Or would it depend on how much deleting/inserting/accessing etc you were expecting to do?
(Hopefully this isn't too much of a nooby question :p)
Thanks in advance
So far I have been making a 'Zelda: A link to the past' rip off, and have been creating new Gaurd Sprites whenever you press the 'n' key, all of them would be deleted from memory when the program is closed.
But I started to wonder if it really matters whether I use a 'list' or 'vector' to store these new sprites?
On cprogramming.com it says:
Which leads me to believe that both should be perfectly fine, but being new to this I'm not 100% sure.You might wonder why there are both list and vector containers in the STL -- the reason is that the underlying representations are different, and each representation has its own costs and benefits. The vector has relatively costly insertions into the middle of the vector, but fast random access, whereas the list allows cheap insertions, but slow access (because the list has to be traversed to reach any item).
So far I have only used a list to store these new sprites, but is there really much difference as to which one to use when it comes to games?
Or would it depend on how much deleting/inserting/accessing etc you were expecting to do?
(Hopefully this isn't too much of a nooby question :p)
Thanks in advance