Loop iteration v's vectors

This is a discussion on Loop iteration v's vectors within the C++ Programming forums, part of the General Programming Boards category; Now that i have the 3d array working its time to do some processing, But after spending some time looking ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    19

    Loop iteration v's vectors

    Now that i have the 3d array working its time to do some processing, But after spending some time looking into different areas i see the its possible to work with vectors in C++


    Is there an advantage of using one over the other(iteration or vectors), if so in what situations. are there any good resources out there.

    Also does any one know a set of classes or library functions optomised for C++ that behave similar to the array manipulation functions in mathlab ie mean( std(

    cheers

    M

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by sononix
    Is there an advantage of using one over the other(iteration or vectors),
    this doesnt really make sense. If you want to access elements in a vector you iterate over those elements using an iterator. Both arrays and vectors use iteration to access all elements.
    An array is a contiguous block of memory, this makes it cache friendly (fast). im not sure about the STL implementation of a vector but id imagine there is more overhead in iterating through it compared to an array. If an array is sufficient (and already working ) then use that.

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>im not sure about the STL implementation of a vector
    I'm not sure either, but I think vectors might use arrays... otherwise I can't think of why insertions/deletion from the middle or beginning of the vector would be slow.

    >but id imagine there is more overhead in iterating through it compared to an array
    Not necessarily. If it's really based on arrays, I'd imagine that the [] operator would be just as fast as an array. And by a similar note, using an iterator as opposed to the [] operator might even be faster, by just incrementing a pointer's position as opposed to incrementing a counter and then (implicitly) using pointer arithmetic to access an individual array element... and although you could do that with arrays anyways, people seldom do.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual Studio Express / Windows SDK?
    By cyberfish in forum C++ Programming
    Replies: 23
    Last Post: 01-22-2009, 01:13 AM
  2. A somewhat bizzare problem!!! - WHILE LOOP
    By bobthebullet990 in forum C Programming
    Replies: 3
    Last Post: 03-31-2006, 06:19 AM
  3. syntax question
    By cyph1e in forum C Programming
    Replies: 19
    Last Post: 03-30-2006, 11:59 PM
  4. kernel iteration through for loop
    By sononix in forum C++ Programming
    Replies: 4
    Last Post: 08-11-2004, 06:16 AM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21