5 ms·
So I was all set to bash include/data-swap.c for allocating on the heap every time you need to swap memory. Turns out that gcc can optimize out that temporary,
by thestoicattack 7y ago
So I was all set to bash include/data-swap.c for allocating on the heap every time you need to swap memory. Turns out that gcc can optimize out that temporary, and it ends up the same as std::swap.
But if we use operator new/delete instead of std::malloc the optimization doesn't take place: https://godbolt.org/z/vtxqD2 https://godbolt.org/z/vtxqD2
- AbacusAvenger 7y agoNeat find. Clang seems to be consistent about it in all 3 cases though: https://godbolt.org/z/iH7ydo https://godbolt.org/z/iH7ydo