Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > std::vector / std::list - just wondering...

Reply
Thread Tools

std::vector / std::list - just wondering...

 
 
Morten Aune Lyrstad
Guest
Posts: n/a
 
      08-24-2004
Hi! I haven't been using the standard template libraries much. I have a hard
time trying to figure out just what is the practical difference between
std::vector and std::list. Aren't both basically a list of objects? Why the
two types? And most importantly of all: Which one is the faster? Is it
practical to use these in game programming for dynamic arrays, or are they
too slow?

Yours,
Morten Aune Lyrstad


 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      08-24-2004
Morten Aune Lyrstad wrote:

> Hi! I haven't been using the standard template libraries much. I have
> a hard time trying to figure out just what is the practical difference
> between std::vector and std::list. Aren't both basically a list of
> objects?


Yes.

> Why the two types?


They store the data in different ways. std::vector stores the data as an
array internally, whereas std::list stores it as a doubly linked list.

> And most importantly of all: Which one is the faster?


That depends on how you want to use them. That's the major reason for
both being available. In std::list, you can efficiently insert and
remove elements at arbitrary positions, while a vector only provides
that for adding or removing elements at the end. OTOH, vector provides
better locality of data (usually meaning better cache efficiency) and
supports direct access to the n-th element for any n between 0 and the
size of the vector, while a list must be traversed for that. There are
some other differences.

> Is it practical to use these in game programming for dynamic arrays,
> or are they too slow?


They can be efficient when used correctly. Sometimes, it might be better
to roll your own if you have special needs, but in many cases, standard
containers are sufficient. After all, they are general-purpose
containers and most implementations are heavily tested and optimized,
resulting in good stability and efficiency.


 
Reply With Quote
 
 
 
 
Morten Aune Lyrstad
Guest
Posts: n/a
 
      08-24-2004
Thanks alot, that cleared everything up nicely!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it just me or just Microsoft? Ark Khasin C++ 24 07-16-2007 11:11 AM
How do I clean a virus within an inbox or just clean only that infectedattachment or LOCATE AND delete just that attachment ? Vinayak Firefox 1 08-14-2006 06:19 PM
Is there a Python MVC that works just as well with just CGI, or FCGI? walterbyrd Python 1 04-10-2006 07:57 PM
allow you to move just about any music to your iPud, MP3 player , or just burn it to disk sbcmynews Computer Support 4 05-01-2005 03:53 PM
Just bought a Digital Rebel just 1 question RacerX Digital Photography 7 11-21-2003 01:51 PM



Advertisments