What is the difference between memmove and memcpy? Which one do you usually use and how?
What is the difference between memmove and memcpy ? Which one do you usually
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
With
memcpy, the destination cannot overlap the source at all. Withmemmoveit can. This means thatmemmovemight be very slightly slower thanmemcpy, as it cannot make the same assumptions.For example,
memcpymight always copy addresses from low to high. If the destination overlaps after the source, this means some addresses will be overwritten before copied.memmovewould detect this and copy in the other direction – from high to low – in this case. However, checking this and switching to another (possibly less efficient) algorithm takes time.