std::vector fast access

Discussion in 'C++' started by Chris Forone, Jul 12, 2008.

  1. Chris Forone

    Chris Forone Guest

    hello group,

    for std::vector, what access is faster from experience, the index or via
    iterator?

    thanks!

    cheers, chris
    Chris Forone, Jul 12, 2008
    #1
    1. Advertising

  2. Chris Forone wrote:
    > for std::vector, what access is faster from experience, the index or via
    > iterator?


    Why don't you measure it?

    In most implementations, when not compiling in debug mode, indexing a
    std::vector is basically a "pointer[index]" operation, and using an
    iterator is identical to using a pointer. Which one is faster depends on
    a lot of things.
    Juha Nieminen, Jul 12, 2008
    #2
    1. Advertising

  3. Chris Forone

    Daniel T. Guest

    On Jul 12, 6:11 am, Chris Forone <> wrote:

    > for std::vector, what access is faster from experience, the index or via
    > iterator?


    I'd be suprised if there is any measurable difference at all,
    especially in a real world application.
    Daniel T., Jul 12, 2008
    #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. Anonymous
    Replies:
    20
    Views:
    4,288
    Pete Becker
    Mar 30, 2005
  2. Jason Heyes
    Replies:
    8
    Views:
    717
    Andrew Koenig
    Jan 15, 2006
  3. Replies:
    8
    Views:
    1,912
    Csaba
    Feb 18, 2006
  4. Juha Nieminen
    Replies:
    22
    Views:
    1,019
    Kai-Uwe Bux
    Oct 12, 2007
  5. Rune Allnor
    Replies:
    4
    Views:
    940
    Rune Allnor
    Dec 11, 2008
Loading...

Share This Page