We are working on open-sourcing an api gateway and using Netty as underlying framework.
I came across Norman Maurer slides. In one of the slides, he mentioned
Only use heap buffers if need to operate on byte[] in ChannelOutboundHandler! By default direct ByteBuf will be returned by ByteBufAllocator.buffer(...).
Take this as rule of thumb
What is the reason behind this thumb of rule ?
The important part is "if need to operate on byte[]". As only when using heap ByteBuf
s it's possible to use byteBuf.array()
to access the underlying byte[]
without doing and extra memory copy.