* why use memcpy when memmove is there?
@ 2007-08-13 10:55 sk malik
2007-08-13 14:15 ` Jan Engelhardt
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: sk malik @ 2007-08-13 10:55 UTC (permalink / raw)
To: linux-kernel
Hi, All
We were looking at "[kernel]/lib/string.c"
(http://lxr.linux.no/source/lib/string.c#L500)
memcpy copies a part of memory to some other location
but It will not work for all cases of overlapping
blocks.(if the start of destination block falls
between the source block)
while memove copes with overlapping areas.
then why is memcpy present in the sources can't we
simply do
"#define memcpy memmove" in include/linux/string.h
or am I missing something?
Regards
Sri
Unlimited freedom, unlimited storage. Get it now, on http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: why use memcpy when memmove is there?
2007-08-13 10:55 sk malik
@ 2007-08-13 14:15 ` Jan Engelhardt
2007-08-13 15:02 ` Stefan Richter
2007-08-14 21:59 ` David Schwartz
2 siblings, 0 replies; 5+ messages in thread
From: Jan Engelhardt @ 2007-08-13 14:15 UTC (permalink / raw)
To: sk malik; +Cc: linux-kernel
On Aug 13 2007 11:55, sk malik wrote:
>Subject: why use memcpy when memmove is there?
>memcpy copies a part of memory to some other location
>but It will not work for all cases of overlapping
>blocks.(if the start of destination block falls
>between the source block)
>
>while memove copes with overlapping areas.
>
>then why is memcpy present in the sources can't we
>simply do
>
>"#define memcpy memmove" in include/linux/string.h
>
>or am I missing something?
memmove must copy with overlapping memory segments, while memcpy does not, and
can therefore use a different optimization strategy. But that would have been
apparent if you had looked at the code.
Jan
--
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: why use memcpy when memmove is there?
2007-08-13 10:55 sk malik
2007-08-13 14:15 ` Jan Engelhardt
@ 2007-08-13 15:02 ` Stefan Richter
2007-08-14 21:59 ` David Schwartz
2 siblings, 0 replies; 5+ messages in thread
From: Stefan Richter @ 2007-08-13 15:02 UTC (permalink / raw)
To: sk malik; +Cc: linux-kernel
sk malik wrote:
> memcpy copies a part of memory to some other location
> but It will not work for all cases of overlapping
> blocks.(if the start of destination block falls
> between the source block)
>
> while memove copes with overlapping areas.
>
> then why is memcpy present in the sources can't we
> simply do
>
> "#define memcpy memmove" in include/linux/string.h
>
> or am I missing something?
The restriction that memcpy is undefined for overlapping areas (IOW, is
only defined for non-overlapping areas) can be used for optimizations in
memcpy which are not possible in memmove. An example, I suppose:
http://lxr.linux.no/source/arch/m68k/lib/string.c#L79
http://lxr.linux.no/source/arch/m68k/lib/string.c#L146
--
Stefan Richter
-=====-=-=== =--- -==-=
http://arcgraph.de/sr/
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: why use memcpy when memmove is there?
2007-08-13 10:55 sk malik
2007-08-13 14:15 ` Jan Engelhardt
2007-08-13 15:02 ` Stefan Richter
@ 2007-08-14 21:59 ` David Schwartz
2 siblings, 0 replies; 5+ messages in thread
From: David Schwartz @ 2007-08-14 21:59 UTC (permalink / raw)
To: linux-kernel
> Hi, All
>
> We were looking at "[kernel]/lib/string.c"
> (http://lxr.linux.no/source/lib/string.c#L500)
>
> memcpy copies a part of memory to some other location
> but It will not work for all cases of overlapping
> blocks.(if the start of destination block falls
> between the source block)
>
> while memove copes with overlapping areas.
>
> then why is memcpy present in the sources can't we
> simply do
>
> "#define memcpy memmove" in include/linux/string.h
>
> or am I missing something?
Suppose you have two vehicles, an economy car and a semi truck. The truck
can go everyplace the car can go, and the truck can carry a bigger load. So
why would you ever use the car? Answer: The car uses less gas and you don't
always need a truck.
Think about what it takes to be able to copy one block of memory to another
location when those locations might overlap. You don't always need that.
DS
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-08-14 22:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <fa.tH0XPZg4jvmqSQh3iOmzbwrRN9Y@ifi.uio.no>
2007-08-13 14:33 ` why use memcpy when memmove is there? Robert Hancock
2007-08-13 10:55 sk malik
2007-08-13 14:15 ` Jan Engelhardt
2007-08-13 15:02 ` Stefan Richter
2007-08-14 21:59 ` David Schwartz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox