[Gluster-devel] Can we replace strcpy calls with memcpy?

Anand Subramanian ansubram at redhat.com
Tue Mar 25 07:34:49 UTC 2014


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:
> Hi List,
>
> In GlusterFS codebase, strcpy() calls have been used in many places. 
> IMO, if we can replace strcpy calls with memcpy() we would get a 
> performance bonus as memcpy directly interacts with memory area. I am 
> posting this suggestion based on my earlier project experience where 
> we have seen a significant difference of performance with this replace.
>
> Please feel free to add if you think otherwise.
>
> Regards,
> Atin Mukherjee
> Senior Software Engineer
> E-9, Extn : 73196, Direct : 08039245196, Mobile: +919739491377
> Email - amukherj at redhat.com
>
>
>
> _______________________________________________
> Gluster-devel mailing list
> Gluster-devel at nongnu.org
> https://lists.nongnu.org/mailman/listinfo/gluster-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://supercolony.gluster.org/pipermail/gluster-devel/attachments/20140325/d080602b/attachment-0001.html>


More information about the Gluster-devel mailing list