void *Memcpy(void *dest, const void *src, size_t count)
{
cout<<"sizeof(dest)是:"<<sizeof(dest)<<endl;
int bytelen=count/sizeof(dest); /*按CPU位宽拷贝*/
int slice=count%sizeof(dest); /*剩余的按字节拷贝*/
unsigned int* d = (unsigned int*)dest;
unsigned int* s = (unsigned int*)src;
if (((int)dest > ((int)src+count)) || (dest < src))
{
while (bytelen--)
*d++ = *s++;
while (slice--)
*(char *)d++ = *(char *)s++;
}
else /* overlap重叠 */
{
d = (unsigned int*)((unsigned int)dest + count - 4); /*指针位置从末端开始,注意偏置 */
s = (unsigned int*)((unsigned int)src + count -4);
while (bytelen --)
*d-- = *s--;
d++;s++;
char * d1=(char *)d;
char * s1=(char *)s;
d1--;s1--;
while (slice --)
*(char *)d1-- = *(char *)s1--;
}
return dest;
}