STL Container to use?

Discussion in 'C++' started by wackyphill@yahoo.com, May 18, 2005.

  1. Guest

    For quick sequential access thru the collection which is best?
    I know Vector is good for random access but I'll almost always be
    working thru all objects in a loop.

    Thanks.
    , May 18, 2005
    #1
    1. Advertising

  2. Rolf Magnus Guest

    wrote:

    > For quick sequential access thru the collection which is best?


    This is the one thing that is quick in pretty much any container.

    > I know Vector is good for random access but I'll almost always be
    > working thru all objects in a loop.


    What about adding or removing elements? Does that happen often? If not,
    stick with vector.
    Rolf Magnus, May 18, 2005
    #2
    1. Advertising

  3. Guest


    > What about adding or removing elements? Does that happen often? If

    not,
    > stick with vector.

    No, mostly all at startup. So Vector it is I guess. Thanks.
    , May 18, 2005
    #3
  4. Code4u Guest

    On 18 May 2005 07:10:44 -0700, wrote:

    >For quick sequential access thru the collection which is best?
    >I know Vector is good for random access but I'll almost always be
    >working thru all objects in a loop.
    >
    >Thanks.


    vector would be the best choice because the storage is guaranteed to
    be contiguous, which in turn means that any sane implementation will
    have very efficient iteration. I've read a good rule of thumb is that
    if you're wondering which container to use, most of the time vector
    will be the best choice.
    Code4u, May 19, 2005
    #4
    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. Maitre Bart
    Replies:
    2
    Views:
    519
    Maitre Bart
    Feb 11, 2004
  2. Josh Mcfarlane
    Replies:
    4
    Views:
    300
    Axter
    Dec 7, 2005
  3. Replies:
    4
    Views:
    796
    Daniel T.
    Feb 16, 2006
  4. Replies:
    11
    Views:
    1,159
    Kai-Uwe Bux
    Apr 4, 2006
  5. wolverine
    Replies:
    2
    Views:
    446
    Marcus Kwok
    Jul 24, 2006
Loading...

Share This Page