@kingkong200
do you think a pointer would be more efficient? |
this question gets asked alot.
using array subscripting operator is considered a function call in C++.
a function call has some overhead.
using pointer arithmetic to access array elements is more efficient for performance, but if not carefully examined can generate nasty bugs.
the same is when using dynamically allocated classes like ( string, vector...)
the members of these classes are quite complicated, calling them will sure generate overhead, if you look to squeeze performance out of your program, you might consider using raw pointers, and pointer arithmetic.
keep in mind:
about 1->10 000 function calls can be acceptable, and would add only little to running time, using standard container classes is good in this situation and doesn't contain a lot of overhead.
but let's say you need to cycle through 10 000 000 elements and do some processing on them.
if you use a vector, it can be considerable overhead, here you might consider using pointer arithmetic and normal arrays to avoid all this overhead and squeeze every drop of performance out of your program.