John McKown wrote:
If I am copying literal text into a char array, which do you think is
better:
strcpy(dest,"LITERAL");
OR
memcpy(dest,"LITERAL",8);
?? I lean towards memcpy because the C run-time reference says that it is
a builtin function and done in-line. Which I would guess would mean better
performance. Why don't I just look at the generated code? Because I don't
have a C compiler for z/OS. I'm writing my code on Linux using GCC.
strcpy() has to test for the end of the string at every interation,
memcpy() copies the specified number of characters (no test.) So, the
"generic" answer to your question is that memcpy() would be faster.
But - as with almost every question in the compiler-world, the answer
is "it depends."
For example - with builtin functions; both of these could use machine
instructions (on generic platform X) that accomplish the copying and
testing without significant penalty... so that strcpy() could be
as fast as memcpy(), particularly for small-sized items.
But - to provide the "generic" answer again; if you know a-priori
the size of a datum, use memcpy().
- Dave Rivers -
p.s. I believe strcpy() is also a builtin function for GCC. It is for
Systems/C for z/Linux.
--
[EMAIL PROTECTED] Work: (919) 676-0847
Get your mainframe programming tools at http://www.dignus.com
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html