Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualfrob

Posted 28 July 2014 - 07:26 AM

A std::vector is a kind of dynamic array. One of the key aspects is that the size can be changed.

Even with a standard array you have iterators. The other features you mentioned are mostly just syntactic candy. If you need to initialize each one then you do it. Passing it to the constructor of a vector just means that the constructor is running that loop instead of you.

If you have no need to resize the container then a simple fixed array works just fine.

If you do need to resize the container use the vector class or a container that works better for your usage patterns. The vector class will do all the work necessary to resize it, including the process of allocating new memory, moving all the objects over to the new block of memory, and releasing the old block of memory.

#1frob

Posted 28 July 2014 - 07:24 AM

A std::vector is a kind of dynamic array. One of the key aspects is that the size can be changed.

Even with a standard array you have iterators.

If you have no need to resize the container then a traditional array works just fine. If you do need to resize the container, the vector class will do all the work necessary to resize it, including the process of allocating new memory, moving all the objects over to the new block of memory, and releasing the old block of memory.

PARTNERS