Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!mcsun!unido!infbs!ramz!ruediger From: ruediger@ramz.UUCP (Ruediger Helsch) Newsgroups: comp.lang.c Subject: Re: memcpy versus assignment Message-ID: <1175@ramz.UUCP> Date: 3 Jan 90 17:12:52 GMT References: <1657@uwm.edu> <1989Dec31.005904.1910@utzoo.uucp> Reply-To: ruediger@ramz.UUCP (Ruediger Helsch) Organization: TU Braunschweig Mechanikzentrum, Germany Lines: 32 In article <1989Dec31.005904.1910@utzoo.uucp> henry@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!