0

I found out that using ByteBuf derived from ChannelHandlerContext behaves exactly the same as when using ByteBuf created via Unpooled for example.

That is, both of these two works:

ctx.write(ctx.alloc().buffer().writeBytes("Hello World".getBytes()))
ctx.write(Unpooled.wrappedBuffer("Hello World".getBytes()))

Is there any difference in the behaviour when ByteBuf retrieved from ctx.alloc().buffer() is used versus any other means of creating a BytBuf?

4

1 回答 1

2

使用ChannelHandlerContextByteBufAllocator配置的Channel。默认情况下使用PooledByteBufAllocatorwhich 意味着出于性能原因缓冲缓冲区。

于 2021-03-26T15:11:22.830 回答