Stories
Slash Boxes
Comments

SoylentNews is people

Submission Preview

Link to Story

strlcpy and how CPUs can defy common sense

Accepted submission by owl at 2024-07-24 21:13:17
Software
https://nrk.neocities.org/articles/cpu-vs-common-sense [neocities.org]

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.


Original Submission