Is there any disadvantages if I'm using Array instead of Vector?

c, c++, memory

Solution

`Vector` adds value in 2 aspects:

- Provides additional functionality which is not present in `C` array, such as resizing, checking for current size etc. You may find better alternatives from its interface to your custom solution.

- Catches some bugs, such as addressing an address beyond the scope of the `vector`.

If you are satisfied with your proprietary data management and confident in quality of your code, you don't need `vector`. Note, though, this might pose some software issues, such as decreased maintainability of `C` array compared to `vector` (e.g., future code may access an out of bounds value, even if your current code doesn't).

Edit: See @Als answer for a possible alternative in your case (`std::array`).

Problem

I wrote a MPC controller in C++, which included a Matrix class, where I stored the data in an array and I used C memory functions(memcpy, memset etc). Today I replaced the array with c++ vector and I used copy to move the memory etc... I faced one problem, by replacing the array with vector the calculation time of the control signal almost doubled by using vector. Is there any disadvantages if I'm using alloc,memcpy,memset, free ins c++ code? If there is any what are those?

Original source