Decreased performance for using a C ++ vector instead of a C array

Is there a performance limitation for working with a vector from the standard library in C ++ instead of arrays in C?

+2


source to share


2 answers


No, no (assuming you compile optimally, so nesting may occur) if you mean "dynamically sized" C arrays obtained with malloc.



Fixed-size matrices in C will have the slight advantage that their address is fixed after being bound (if global) or that they live directly on the stack rather than indirectly through a pointer to what's on the heap. I believe there is still no performance difference; constant base addresses are no faster than variables; both are loaded into the CPU register.

+7


source


The only real difference is that std :: vector calls go through trivial functions. As long as you use the appropriate level of optimization so that these function calls are inserted, they will be the same.



+1


source







All Articles