1

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 ?

vkohli
  • 65
  • 7

1 Answers1

2

The important part is "if need to operate on byte[]". As only when using heap ByteBufs it's possible to use byteBuf.array() to access the underlying byte[] without doing and extra memory copy.

Norman Maurer
  • 23,104
  • 2
  • 33
  • 31