3 ms·
In this case the code was using the .data() on a std::vector<char>, so it wouldn't have even been possible to use something like std::stoi (or something nicer l
by eklitzke 4y ago
In this case the code was using the .data() on a std::vector<char>, so it wouldn't have even been possible to use something like std::stoi (or something nicer like absl::SimpleAtoi) since the C++ routines need a std::string (or absl will accept std::string_view), not a C style string. Which in itself shows you that the code is problematic, because it's been written in a way where you can't even use idiomatic C++ library functions to do basic tasks.
For the memcpy() thing the idiomatic way would have been to use std::copy() with the vectors begin/end iterators, and std::copy will do the right thing in this situation with a zero sized vector. The compiler will generate the same code with std::copy() as memcpy() anyway if the vector contains a POD type (as it did in this example), so there's not even a performance argument to be made for memcpy().