473,395 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

diff memcpy and memmove

Please explain with an example whts the
DIFFERENCE between "memcpy" and "memmove"

Mar 10 '06 #1
6 6062
"novice" <no********@gmail.com> writes:
Please explain with an example whts the
DIFFERENCE between "memcpy" and "memmove"


memcpy() invokes undefined behavior if it attempts to copy between
objects that overlap. memmove() works as if by copying the source
object to a temporary array and then copying the temporary array to
the target object (though it probably will do the copy directly, being
careful about the order in which bytes are copied).

This should be explained in your textbook, your system's
documentation, or by a quick Google search.

--
Keith Thompson (The_Other_Keith) ks***@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.
Mar 10 '06 #2
On Friday 10 March 2006 06:36, novice opined (in
<11**********************@j52g2000cwj.googlegroups .com>):
Please explain with an example whts the
DIFFERENCE between "memcpy" and "memmove"


Smells like homework assignment. Make an effort, and DIY.

Here's one: "memcpy" is a string literal that takes 6 bytes (one for
each letter, and one for terminating '\0'), and "memmove" takes 7.

And here's what the Standard has to say about the functions that go by
the names of `memcpy` and `memmove`:

7.21.2.1 The memcpy function
Synopsis
#include <string.h>
void *memcpy(void * restrict s1,
const void * restrict s2,
size_t n);
Description
The memcpy function copies n characters from the object pointed to by
s2 into the object pointed to by s1. If copying takes place between
objects that overlap, the behavior is undefined.

Returns
The memcpy function returns the value of s1.

7.21.2.2 The memmove function
Synopsis
#include <string.h>
void *memmove(void *s1, const void *s2, size_t n);
Description
The memmove function copies n characters from the object pointed to by
s2 into the object pointed to by s1. Copying takes place as if the n
characters from the object pointed to by s2 are first copied into a
temporary array of n characters that does not overlap the objects
pointed to by s1 and s2, and then the n characters from the temporary
array are copied into the object pointed to by s1.

Returns
The memmove function returns the value of s1.

In short, use `memmove` when you're not sure that the memory regions do
not overlap. You can surely come up with an example yourself.

(Also, no need to SHOUT at us.)

--
BR, Vladimir

Langsam's Laws:
(1) Everything depends.
(2) Nothing is always.
(3) Everything is sometimes.

Mar 10 '06 #3
On Friday 10 March 2006 06:36, novice opined (in
<11**********************@j52g2000cwj.googlegroups .com>):
Please explain with an example whts the
I don't know what `whts` means so my previous reply may have been
completely wrong. Please do not use silly abrvtns.
DIFFERENCE between "memcpy" and "memmove"


--
BR, Vladimir

QOTD:
All I want is more than my fair share.

Mar 10 '06 #4
On Friday 10 March 2006 07:11, Vladimir S. Oka opined (in
<du**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com>):
On Friday 10 March 2006 06:36, novice opined (in
<11**********************@j52g2000cwj.googlegroups .com>):
Please explain with an example whts the
DIFFERENCE between "memcpy" and "memmove"


Smells like homework assignment. Make an effort, and DIY.

Here's one: "memcpy" is a string literal that takes 6 bytes (one for
each letter, and one for terminating '\0'), and "memmove" takes 7.


Too early in the morning. Should've said 7 and 8 respectively. :-(

--
BR, Vladimir

For my birthday I got a humidifier and a de-humidifier. I
put them in the same room and let them fight it out.
-- Steven Wright

Mar 10 '06 #5
In article <du**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com>,
Vladimir S. Oka <no****@btopenworld.com> wrote:
Please explain with an example whts the
I don't know what `whts` means so my previous reply may have been
completely wrong. Please do not use silly abrvtns.


Presumably it was a typo for "whats", which in turn should have been
"what's".

-- Richard
Mar 10 '06 #6
novice wrote:
Please explain with an example whts the
DIFFERENCE between "memcpy" and "memmove"


Always check the FAQs before posting questions of this nature:

http://c-faq.com/ansi/memmove.html
Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Mar 10 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: franky.backeljauw | last post by:
Hello, following my question on "std::copy versus pointer copy versus member copy", I had some doubts on the function memcpy, as was used by tom_usenet in his reply. - Is this a c++ standard...
2
by: rinku24 | last post by:
What is the difference between memcpy and memmove? Which is more expensive?
71
by: ROSY | last post by:
1. How would you use the functions memcpy(), memset(), memmove()?
21
by: Mac | last post by:
$ cat junk27.c #include <stdio.h> #include <string.h> int main (void) { printf("The difference between memcpy and memmove is %ld\n", (long int) memcpy - (long int) memmove); return 0; }
5
by: xdevel | last post by:
Hi, anyone can make me an example where memmove does not cause a memory overlapping and where memcpy do it? Thanks
14
by: somenath | last post by:
Hi All, I am trying to understand the behavior of the memcpy and memmove. While doing so I wrote a program as mentioned bellow . #include<stdio.h> #include<stdlib.h> #include<string.h> ...
8
by: mthread | last post by:
Hi, I am copying data from one buffer(this data is a binary data not string) to another buffer. Earlier when I used C, I used the memcpy function call to copy the values. Is there any equivalent...
18
by: sam | last post by:
(newbie)Technically what's the difference between memset() and memcpy() functions?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.