mercredi 21 décembre 2016

What performance can I expect from std::fill_n(ptr, n, 0) relative to memset(ptr, 0, n)?

For an iterator ptr which is a pointer, std::fill_n(ptr, n, 0) should do the same thing as memset(ptr, 0, n) (but see @KeithThompson's comment on this answer).

For a C++ compiler in C++11/C++14/C++17 mode, under which conditions can I expect these to be compiled to the same code? And when/if they don't compile to the same code, is there a significant performance difference with -O0? -O3?

Note: Of course some/most of the answer might be compiler-specific. I'm only interested in one or two specific compilers, but please write about the compiler(s) for which you know the answer.

Aucun commentaire:

Enregistrer un commentaire