首页 > 代码库 > 内存拷贝实现

内存拷贝实现

void* memove(void* dest,const void*src,size_t count){    assert((dest != NULL) && (src != NULL));    assert(count>0);    char* psrc = http://www.mamicode.com/(char*)src;    char* pdest = (char*)dest;    //检查是否有重叠问题       if(pdest < psrc)    {        //正向拷贝           while(count--)            *pdest++ = *psrc++;    }    else if(psrc < pdest)    {        //反向拷贝           psrc = http://www.mamicode.com/psrc + count -1;        pdest = pdest + count -1;        while(count--)            *pdest-- = *psrc--;    }    return dest;}void* memmcpy(void* dest,const void* src,size_t count){    assert((dest != NULL) && (src != NULL));    assert(count > 0);    char* psrc = http://www.mamicode.com/(char*)src;    char* pdest = (char*)dest;    while(count --)        *pdest++ = *psrc++;    return dest;}
View Code

 

内存拷贝实现