Results 1 to 6 of 6
hi,
can anyone explain me what strcpy() & memcpy() actually does?plzz reply me soon.........
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-05-2005 #1Just Joined!
- Join Date
- Aug 2005
- Posts
- 19
difference between strcpy() and memcpy()
hi,
can anyone explain me what strcpy() & memcpy() actually does?plzz reply me soon......
- 09-05-2005 #2Linux User
- Join Date
- Aug 2005
- Location
- Italy
- Posts
- 401
no difference
Functionally there's no difference: both copy memory from a location to another...
The main difference is the function declaration... probably also implementation differs, and memcpy should reasonably faster than strcpy, because strcpy must stop when encounter the first '\0' character, so it must test char by char (or something similar), while memcpy can optimize using memory alignement and other stuffs...When using Windows, have you ever told "Ehi... do your business?"
Linux user #396597 (http://counter.li.org)
- 09-08-2005 #3Just Joined!
- Join Date
- Sep 2005
- Location
- China
- Posts
- 2
Hi,In Chinese:
strcpy包含两个参数,无法确定要拷贝的字节数,而只能通过识别'\0'来完成一次拷贝。
memcpy的函数中包含要拷贝的字节数,80x86下是用rep movsb实现的,拷贝的速度相对要快些。
- 09-10-2005 #4Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Huh? One copies a block of memory, and the other copies a sequence of bytes, terminating on a NULL character. Quite a big difference, I'd have thought, if you're writing code that has to work.Functionally there's no difference
- 09-13-2005 #5Linux Newbie
- Join Date
- May 2005
- Location
- Chennai,TamilNadu, India
- Posts
- 141
while using memcpy be careful since u have to check the destination size and source size which ever is greater or smaller and according to that do the memcpy and insert the '\0' character at the end after the memcpy when copying strings
- 09-13-2005 #6Linux Newbie
- Join Date
- May 2005
- Location
- Chennai,TamilNadu, India
- Posts
- 141
I just got an example of what i had done previously
Its something like this
memcpy(dest, src,sizeof(dst));
if(strlen(src)>sizeof(dest))
{
dest[sizeof(dest)-1]='\0';
}
else
{
dest [strlen(src)]='\0';
}
same thing can be applicable for memmove but memory areas overlap in that


Reply With Quote
