strlcpy and How CPUs Can Defy Common Sense
owl writes:
https://nrk.neocities.org/articles/cpu-vs-common-sense
Recently one of my older post about strlcpy has sparked some discussion on various forums. Presumably the recently released POSIX edition had something to do with it. One particular counter-argument was raised by multiple posters - and it's an argument that I've heard before as well:
In the common case where the source string fits in to the destination buffer, strlcpy would only traverse the string once whereas strlen + memcpy would traverse it twice always.
Hidden in this argument is the assumption that traversing the string once is faster. Which - to be clear - is not at all an unreasonable assumption. But is it actually true? That's the focus of today's article.
Read more of this story at SoylentNews.