Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C google snappy增量复制函数_C_Snappy - Fatal编程技术网

C google snappy增量复制函数

C google snappy增量复制函数,c,snappy,C,Snappy,下面的代码来自google snappy的snappy.cpp,有人能解释一下下面的函数如何使用len字节从src得到结果吗 // Copy "len" bytes from "src" to "op", one byte at a time. Used for // handling COPY operations where the input and output regions may // overlap. For example, suppose: // src ==

下面的代码来自google snappy的snappy.cpp,有人能解释一下下面的函数如何使用len字节src得到结果吗

// Copy "len" bytes from "src" to "op", one byte at a time.  Used for
// handling COPY operations where the input and output regions may
// overlap.  For example, suppose:
//    src    == "ab"
//    op     == src + 2
//    len    == 20
// After IncrementalCopy(src, op, len), the result will have
// eleven copies of "ab"
//    ababababababababababab
// Note that this does not match the semantics of either memcpy()
// or memmove().
static inline void IncrementalCopy(const char* src, char* op, ssize_t len) {
  assert(len > 0);
  do {
    *op++ = *src++;
  } while (--len > 0);
}

它不复制src的len个副本。它复制len字节。它是
memcpy
的未优化版本。我想需要一个单独的函数的原因是
memcpy
有很多优化,这些优化在这样的边缘情况下不起作用。是的,我的意思是相同的(len字节-编辑了相同的问题),src在3次迭代后不会达到“\0”,副本是如何工作的。我尝试了一个简单的程序,但它只产生src值,而不是指定的len字节。这个函数是为了防止输入和输出区域重叠。在给出的示例中,
op==src+2
因此对于第三个循环,
dest[2]
被设置为等于先前设置的
dest[0]
(即
a