Q:

Buffer types for MessageToByteEncoder in Netty

I've been reading Norman Maurer's presentation on Netty best practices and had a question about using direct buffers versus heap buffers. One slide recommends "always use direct ByteBuffer when writing to SocketChannel," but another encourages using heap buffers when using MessageToByteEncoder. I don't think I quite get the nuances in the second slide; in the MessageToByteEncoder case, why does using heap buffers "save extra byte copies?"
Thanks!

A:

using heap-buffers may make sense if you need to act directly on the backing array. This is for example true when you use deflater/inflater as it only acts on byte[]. For all other cases a direct buffer is prefered.

