Re:C++ for Games: Performance, Allocations and Data Locality
by exDM69 on Monday May 30, 2016 @04:07AM
(#11800183)
For std::vector, they should compile to the same thing, the iterator is just a pointer to a flat array. For std::map (ie. red-black tree) or something more complex, it might make a bigger difference. But even then, the iterator is quite light weight (just a pointer) so copying it is not a big deal.
Re:C++ for Games: Performance, Allocations and Data Locality
by nandno on Monday May 30, 2016 @05:45AM
(#11800495)
Even for std::map gcc generates identical code:
godbolt is a great resource to see just how good modern compilers are.
Re:C++ for Games: Performance, Allocations and Data Locality
by SamReidHughes on Monday May 30, 2016 @10:14PM
(#11804195)
I wouldn't say "even" -- that's just another type where the iterator is a trivially copyable/destructable object.
Post increment: https://godbolt.org/g/k5rcPA
Pre increment: https://godbolt.org/g/WgfMzU