A simple rule of when I should use direct buffers with Java NIO for network I/O?

后端 未结 2 965
盖世英雄少女心
盖世英雄少女心 2021-01-05 01:48

Can someone with the natural gift to explain complex things in an easy and straightforward way address this question? To acquire the best performance when should I use direc

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-05 02:34

    A direct buffer is best when you are just copying the data, say from a socket to a file or vice versa, as the data doesn't have to traverse the JNI/Java boundary, it just stays in JNI land. If you are planning to look at the data yourself there's no point in a direct buffer.

提交回复
热议问题