|
From: | Anand Subramanian |
Subject: | Re: [Gluster-devel] Can we replace strcpy calls with memcpy? |
Date: | Tue, 25 Mar 2014 13:04:49 +0530 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 |
While we may be tempted to go with the
reason that memcpy is faster (simply because it knows the no of
bytes to be copied in advance and doesn't need to compare each
byte-to-be-copied with a '\0', it is also implementation dependent
and performance could vary depending on if assembler optimizations
to copy several bytes at once are used or not), please note that
these are *functionally* different. While strcpy() will stop
copying on encountering the null terminator, memcpy will copy the
number of bytes passed in past the termination character. They are
meant for different things IMHO, depending on what you want :) In
general its probably better practice to stick to strcpy (or even
better, strncpy) when dealing with strings.
Anand On 03/24/2014 12:35 PM, Atin Mukherjee wrote:
|
[Prev in Thread] | Current Thread | [Next in Thread] |