resort on a std::vector vs std::insert
- by Abruzzo Forte e Gentile
I have a sorted std::vector of relative small size ( from 5 to 20 elements ).
I used std::vector since the data is continuous so I have speed because of cache.
On a specific point I need to remove an element from this vector.
I have now a doubt: which is the fastest way to remove this value between the 2 options below?
setting that element to 0 and call sort to reorder: this has complexity but
elements are on the same cache line.
call erase that will copy ( or memcpy who knows?? ) all elements after it
of 1 place ( I need to investigate the behind scense of erase ).
Do you know which one is faster?
I think that the same approach could be thought about inserting a new element without hitting the max capacity of the vector.
Regards
AFG