gluster-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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:
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



_______________________________________________
Gluster-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/gluster-devel


reply via email to

[Prev in Thread] Current Thread [Next in Thread]