memmove()
has to spend some time determining how and whether the source and target overlap, so it can decide the order in which to copy the data.
Hypothetically, a version of memmove()
that omits this initial calculation, either because it assumes a particular direction or because it has an extra parameter that lets you tell it, might be a little faster than memmove()
.
But there is no such function in the standard library.
You could write your own function, but it's unlikely that it would be as fast as your system's memmove()
, which is very likely to be heavily optimized. You could grab a copy of the source code for your system's memmove()
function (if it's available) and modify it, but the result would likely be non-portable (memmove()
can depend on the characteristics of the system it's running on).
But it's very unlikely that it would be worth the effort. The time memmove()
spends doing the initial calculation is, for moves of reasonable size, likely to be a small fraction of the time spent copying the data.
Unless you know from actual measurement that the initial computation performed by memmove()
carries a significant performance penalty for your program, just use memmove()
itself.
memmove
"not the best"? – user2864740dest
andsrc
as a pre-condition for proper operation: sourceware.org/bugzilla/show_bug.cgi?id=12518 I'd suggest just usingmemmove()
- what is a correct positioning ofdest
andsrc
today becomes a different positioning in several months when the code is modified by someone unaware of the importance of what is nearly always a minor detail taken care of by the compiler, linker, or OS. – Michael Burrmemmove
has to correct position of thesource
anddest
in order to prevent the overlapping problem. That's unnecessary in my case. – user1134316memcpy(*source + 2, *source, 3)
– user1134316