Netty 的 ByteBuf.copy() 和 ByteBuf.duplicate() 的区别
Difference between Netty's ByteBuf.copy() and ByteBuf.duplicate()
乍一看,他们似乎很相似。我的理解是 copy()
会创建底层内容的副本,而 duplicate()
不会。那是准确的吗?在什么情况下你会使用其中一个对比另一个?
复制()
Returns a copy of this buffer's readable bytes. Modifying the content of the returned buffer or this buffer does not affect each other at all.
复制()
Returns a buffer which shares the whole region of this buffer. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method does not modify readerIndex or writerIndex of this buffer.
当您想要完全独立的 ByteBuf 对象副本时,您可以使用 copy() 方法。
更多信息可以从ByteBuf documentation
找到
乍一看,他们似乎很相似。我的理解是 copy()
会创建底层内容的副本,而 duplicate()
不会。那是准确的吗?在什么情况下你会使用其中一个对比另一个?
复制()
Returns a copy of this buffer's readable bytes. Modifying the content of the returned buffer or this buffer does not affect each other at all.
复制()
Returns a buffer which shares the whole region of this buffer. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method does not modify readerIndex or writerIndex of this buffer.
当您想要完全独立的 ByteBuf 对象副本时,您可以使用 copy() 方法。
更多信息可以从ByteBuf documentation
找到