memcpy versus assignment
Ruediger Helsch
ruediger at ramz.UUCP
Thu Jan 4 04:12:52 AEST 1990
In article <1989Dec31.005904.1910 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
>On the other hand, many such compilers will generate simple rather than
>optimal copy code for the assignment, while the memcpy() may be well
>optimized once you get past the startup overhead. (In particular, there
>is a naive belief that hardware provisions for fast copy -- string/block
>instructions, "loop mode", etc. -- are always the fastest way to do such
>operations, which is often untrue.
On the other side, you are not sure wether your computers memcpy() uses
the fast hardware instructions. Here follows the Ultrix (3.0) implementation
of memcpy():
/*
* Copy s2 to s1, always copy n bytes.
* Return s1
*/
char *
memcpy(s1, s2, n)
register char *s1, *s2;
register int n;
{
register char *os1 = s1;
while (--n >= 0)
*s1++ = *s2++;
return (os1);
}
VAXen do have fast copy commands, but even copying wordwise would surely
be faster than byte after byte.
P.S.: I hope i didn't break any copyrights!
More information about the Comp.lang.c
mailing list