本身实现的memcpy
没有思量方针和源地点大概反复的环境,不知道除了这个要领之外不消汇编等方法尚有没有更快的要领?至少我今朝是想不出来:)
void *my_memcpy(void *dst, void* src, int size)
{
int len = sizeof(long);
long *pdst = (long*)dst;
long *psrc = (long*)src;
for (; size >= len; ++pdst, ++psrc, size -= len)
{
*pdst = *psrc;
}
for (len = size, size = 0; size < len; ++size)
{
*((char*)pdst + size) = *((char*)psrc + size);
}
return dst;
}
int main()
{
char src[] = "hello", dst[10] = {'\0'};
my_memcpy(dst, src, 5);
printf("dst = %s\n", dst);
return 0;
}