英文:
What's the difference between io.Copy and io.CopyBuffer?
问题
在io.CopyBuffer的文档中提到:
> CopyBuffer与Copy相同,只是它会通过提供的缓冲区(如果需要)进行分阶段操作,而不是分配一个临时缓冲区。
这是否意味着io.CopyBuffer
会先将数据复制到缓冲区,然后再复制到目标位置,从而减少对源Write的调用次数?
英文:
In the documentation of io.CopyBuffer it states:
> CopyBuffer is identical to Copy except that it stages through the
> provided buffer (if one is required) rather than allocating a
> temporary one.
Does that mean that io.CopyBuffer
will copy first to buffer and then into destination making less calls to source Write?
答案1
得分: 2
CopyBuffer允许您分配自己的缓冲区。它与Copy函数的功能相同。如果您查看Copy函数,您会发现它只是调用CopyBuffer函数。
CopyBuffer允许您选择自己的缓冲区大小。io.Copy函数默认使用32K的缓冲区。如果您知道要复制的内容很大,使用更大的缓冲区可能会提高性能。除了允许调用者控制缓冲区的大小外,调用者还可以将单个缓冲区用于多个复制操作。
英文:
CopyBuffer let’s you allocate your own buffer. It is otherwise the same as
Copy. If you look at Copy, it just calls CopyBuffer.
CopyBuffer let's you choose your own buffer size. io.Copy by default uses a 32K
buffer. If you know your copy will be large, a larger buffer may be more
performant. In addition to allowing the caller to control the size of the
buffer, a caller can use a single buffer for multiple copy operations.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论