concept ByteBufAllocator in category netty

This is an excerpt from Manning's book Netty in Action.
Table 5.7 lists the operations provided by ByteBufAllocator.
Table 5.7. ByteBufAllocator methods
Name
Description
buffer() buffer(int initialCapacity); buffer(int initialCapacity, int maxCapacity); Returns a ByteBuf with heap-based or direct data storage heapBuffer() heapBuffer(int initialCapacity) heapBuffer(int initialCapacity, int maxCapacity) Returns a ByteBuf with heap-based storage directBuffer() directBuffer(int initialCapacity) directBuffer(int initialCapacity, int maxCapacity) Returns a ByteBuf with direct storage compositeBuffer() compositeBuffer(int maxNumComponents); compositeDirectBuffer() compositeDirectBuffer(int maxNumComponents); compositeHeapBuffer() compositeHeapBuffer(int maxNumComponents); Returns a CompositeByteBuf that can be expanded by adding heap-based or direct buffers up to the specified number of components ioBuffer() Returns a ByteBuf that will be used for I/O operations on a socket You can obtain a reference to a ByteBufAllocator either from a Channel (each of which can have a distinct instance) or through the ChannelHandlerContext that is bound to a ChannelHandler. The following listing illustrates both of these methods.
Netty provides two implementations of ByteBufAllocator: PooledByteBufAllocator and UnpooledByteBufAllocator. The former pools ByteBuf instances to improve performance and minimize memory fragmentation. This implementation uses an efficient approach to memory allocation known as jemalloc[4] that has been adopted by a number of modern OSes. The latter implementation doesn’t pool ByteBuf instances and returns a new instance every time it’s called.