Discussion:
memcpy VS RtlCopyMemory
(too old to reply)
Vadym Stetsyak
2003-08-22 11:37:43 UTC
Permalink
Hello!

What routine is faster memcpy or RtlCopyMemory?
Here is the code of the memcpy.c

void * __cdecl memcpy (
void * dst,
const void * src,
size_t count
)
{
void * ret = dst;

#if defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) || defined
(_M_IA64)
{
extern void RtlMoveMemory( void *, const void *, size_t count );

RtlMoveMemory( dst, src, count );
}
#else /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) ||
defined (_M_IA64) */
/*
* copy from lower addresses to higher addresses
*/
while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst + 1;
src = (char *)src + 1;
}
#endif /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) ||
defined (_M_IA64) */

return(ret);
}

In my x86 it looks like memcpy will copy the buffer 1 byte per iteration. It
seems to be rather strange, how will it impact performance?
--
Vadym Stetsyak
PDS
Vadym Stetsyak
2003-08-22 12:21:45 UTC
Permalink
Sorry, didn't followed that thread.
Thanks for the quick answer
Post by Vadym Stetsyak
What routine is faster memcpy or RtlCopyMemory?
Sigh. I thought we ended that discussion a few weeks ago.
If you don't have special requirements, use memcpy(). If using MS
compilers,
make sure the option "generate intrinsic functions" is enabled.
S
Tony Proctor
2003-08-22 12:34:58 UTC
Permalink
That C code doesn't cope with 'destructive overlap', but I'm pretty certain
that memcpy is defined as coping properly with it.

Basically, if the code deals with destructive overlap, then it should copy
'backwards' (i.e. working from end of buffer to start of buffer) if dst >
src, and copy 'forwards' if dst < src

Tony Proctor
Post by Vadym Stetsyak
Hello!
What routine is faster memcpy or RtlCopyMemory?
Here is the code of the memcpy.c
void * __cdecl memcpy (
void * dst,
const void * src,
size_t count
)
{
void * ret = dst;
#if defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) || defined
(_M_IA64)
{
extern void RtlMoveMemory( void *, const void *, size_t count );
RtlMoveMemory( dst, src, count );
}
#else /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) ||
defined (_M_IA64) */
/*
* copy from lower addresses to higher addresses
*/
while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst + 1;
src = (char *)src + 1;
}
#endif /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) ||
defined (_M_IA64) */
return(ret);
}
In my x86 it looks like memcpy will copy the buffer 1 byte per iteration. It
seems to be rather strange, how will it impact performance?
--
Vadym Stetsyak
PDS
Slava M. Usov
2003-08-22 12:42:50 UTC
Permalink
Post by Tony Proctor
That C code doesn't cope with 'destructive overlap', but I'm pretty
certain that memcpy is defined as coping properly with it.
Nope. That is a property of memmove(). memcpy() is a light-weight version.

S
Tony Proctor
2003-08-22 13:20:53 UTC
Permalink
:-)

So much for my memory, eh? I guess 'age' does that to people

Tony
Post by Slava M. Usov
Post by Tony Proctor
That C code doesn't cope with 'destructive overlap', but I'm pretty
certain that memcpy is defined as coping properly with it.
Nope. That is a property of memmove(). memcpy() is a light-weight version.
S
Loading...