一、memcpy和memove

C++ 相关的string    函数(memcpy、memove、strtok、strchr、strlcpy)

 

 

void* memove(void*destin , void* source, size_t count) {

    //进行这样的判断是为了解决拷贝重叠的情况
    if (destin > source) {
        //这里拷贝的时候还可以提高效率
        //因为CPU单次可以拷贝的最大字节是8个
        //所以完全可以用long* 替代 char*(前提是count>8)

        char* a = (char*)destin;
        char* b = (char*)source;
        while (count--) {
            *b++ = *a++;
        }
    }
    else
    {
        char* a = (char*)destin + count;
        char* b = (char*)source + count;
        while (count--) {
            *b-- = *a--;
        }
    }
    return destin;
}
memove

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-12
  • 2021-10-31
  • 2021-09-22
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
相关资源
相似解决方案