"naren" <narendar.anumala@gmail.com> writes:[color=blue]
> Iam not getting the correct pros and cons of the strcpy() and memcpy()
> some where i read for short strings strcpy is faster and for large
> strings memcpy is faster..
> in strcpy() there is a single pass over the data...but in memcpy()
> there are 2 passes..one is for strlen() and another is for copying..
> but how memcpy will be faster for large strings?[/color]
memcpy() and strcpy() are functionally different. Use memcpy() if you
already know how many bytes you want to copy. Use strcpy() if you
want to copy a string (i.e., up to the first '\0' character).
If you've already computed the length of your string (with strlen()),
you have a choice -- but it probably doesn't make much difference.
There's no obvious reason why one or the other should be faster,
and it's likely to vary from one system to another.
Use whichever is correct. If they're both correct, use whichever one
is clearer (likely strcpy() if you're dealing with strings). If *and
only if* performance is a problem consider choosing on the basis of
speed, and only after measuring the actual performance.
--
Keith Thompson (The_Other_Keith)
kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.