# 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. ## 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. 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. >>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.