<table class="text">
<tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
10
11 性能以及内存使用降到最低, 此实现使用一个“jemalloc”内存分配。其他的实现不池化 ByteBuf 情况下,每次返回一个新的实例。Netty 默认使用 PooledByteBufAllocator, 我们可以通过 ChannelConfig 或通过引导设置一个不同的实现来改变。” 2. “当未引用 ByteBufAllocator 时,上面的方法无法访问到 ByteBuf。对于这个用例 Netty 提供一个实用工具类称为 Unpooled,它提供了静态辅助方法来创建非池化的 ByteBuf 实例-----Unpooled” 3. “在 非联网项目,该 Unpooled 类也使得它更容易使用的 ByteBuf API,获得一个高性能的可扩展缓冲 API,而不需要 Netty 的其他部分的” 从上面的文字可以了解到,ByteBufAllocator 中的PooledByteBufAllocator 可以很好的提升性能,因此尽量使用PooledByteBufAllocator。 可以:1.从 channel 获得 ByteBufAllocator 2.从 ChannelHandlerContext 获得 ByteBufAllocator 如果无法获得ByteBufAllocator,使用unpooled,使用的目的就是能继续使用ByteBuf提供的API,方便处理。