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

Discussion in 'C++' started by Morten Aune Lyrstad, Aug 24, 2004.

  1. 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
     
    Morten Aune Lyrstad, Aug 24, 2004
    #1
    1. Advertising

  2. Morten Aune Lyrstad

    Rolf Magnus Guest

    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.
     
    Rolf Magnus, Aug 24, 2004
    #2
    1. Advertising

  3. Thanks alot, that cleared everything up nicely! :)
     
    Morten Aune Lyrstad, Aug 24, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. suresh
    Replies:
    1
    Views:
    357
    Karl Seguin
    Apr 14, 2005
  2. =?Utf-8?B?cm9kY2hhcg==?=

    just wondering

    =?Utf-8?B?cm9kY2hhcg==?=, Oct 21, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    430
    =?Utf-8?B?cm9kY2hhcg==?=
    Oct 22, 2005
  3. =?Utf-8?B?YXJp?=

    just wondering

    =?Utf-8?B?YXJp?=, Oct 22, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    380
    =?Utf-8?B?YXJp?=
    Oct 22, 2005
  4. KevinGPO
    Replies:
    2
    Views:
    443
    benben
    Sep 10, 2005
  5. Gediminas Kregzde

    Just wondering

    Gediminas Kregzde, May 15, 2009, in forum: Python
    Replies:
    9
    Views:
    297
    norseman
    May 18, 2009
Loading...

Share This Page