472,342 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

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

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
Jul 22 '05 #1
2 4686
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.
Jul 22 '05 #2
Thanks alot, that cleared everything up nicely! :-)
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: BCC | last post by:
Hi, A colleague has some code like this: class CMyObject { // Bunch of Member functions } class CMyObjectList: public...
11
by: Steve | last post by:
Hi, I'm using a std::vector to store a list of user defined objects. The vector may have well over 1000 elements, and I'm suffering a performance...
5
by: Eric Lilja | last post by:
Hello, consider this complete program (sorry, it's not minimal but I hope it's readable at least): #include <algorithm> #include <iostream>...
17
by: Michael Hopkins | last post by:
Hi all I want to create a std::vector that goes from 1 to n instead of 0 to n-1. The only change this will have is in loops and when the vector...
2
by: Priya Mishra | last post by:
Hi All It was very nice to intract with this group, While in my previous post, I was suggested to reffer the link, in order to learn C++, Well...
9
by: kathy | last post by:
I am using std::vector in my program: func() { std::vector <CMyClass *> vpMyClass; vpMyClass.push_back(new CMyClass());...
4
by: TBass | last post by:
Hi, I've got a class that uses a std::list to store tags that need to be written out to a device. I've had no problem with the lists in terms of...
3
by: jason.cipriani | last post by:
How can I use my own custom comparison function with std::list::sort()? The only call to sort() I see does not take a predicate argument. ...
3
by: Carter | last post by:
I am currently writing some code where I have a list of objects with a maximum occupancy of 4. I have been employing std::vector for this but I was...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.