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?
Vectoradds value in 2 aspects:Carray, such as resizing, checking for current size etc. You may find better alternatives from its interface to your custom solution.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 ofCarray compared tovector(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).