0

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!

Jon Chambers
  • 644
  • 7
  • 14

1 Answers1

1

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.

Norman Maurer
  • 23,104
  • 2
  • 33
  • 31
  • Lucky you...an answer from the man himself :). Also see http://stackoverflow.com/a/5671880/3993966 for a good general description of the differences between direct and non-direct buffers in java. – Scott Mitchell Nov 08 '14 at 21:15