From: Matthew Wilcox <matthew@wil.cx>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] what is best: memcpy or for
Date: Wed, 06 Dec 2006 14:13:04 +0000 [thread overview]
Message-ID: <20061206141303.GT3013@parisc-linux.org> (raw)
In-Reply-To: <80ec54e90612052335v3688faedj6c64f979d420c078@mail.gmail.com>
On Wed, Dec 06, 2006 at 08:35:41AM +0100, Daniel Marjam?ki wrote:
> I am wondering if there is any real difference between "for" and "memcpy"..
>
> int i, a[100], b[100];
>
> // method 1
> for (i = 0; i < 100; i++)
> a[i] = b[i];
>
> // method 2
> memcpy(a, b, sizeof(a));
>
> Is there any difference in speed?
>
> With a good compiler, the output should be the same for both methods,
> shouldn't it?
Yes, gcc has idiom-recognising techniques for that. Possibly not in the
version you're using, though. In any case, the memcpy() gives gcc more
information (that a and b do not overlap) that it would otherwise have
to deduce for itself (it can normally do this, particularly for the
example you gave).
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
next prev parent reply other threads:[~2006-12-06 14:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-06 7:35 [KJ] what is best: memcpy or for Daniel Marjamäki
2006-12-06 8:34 ` Christophe Lucas
2006-12-06 14:13 ` Matthew Wilcox [this message]
2006-12-06 15:25 ` Neil Horman
2006-12-07 4:59 ` Anupam Kapoor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061206141303.GT3013@parisc-linux.org \
--to=matthew@wil.cx \
--cc=kernel-janitors@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.