Java ByteBuffer performance issue

前端 未结 4 1773
臣服心动
臣服心动 2021-01-31 20:46

While processing multiple gigabyte files I noticed something odd: it seems that reading from a file using a filechannel into a re-used ByteBuffer object allocated with allocateD

4条回答
  •  广开言路
    2021-01-31 21:06

    Reading into the direct byte buffer is faster, but getting the data out of it into the JVM is slower. Direct byte buffer is intended for cases where you're just copying the data without actually looking at it in the Java code. Then it doesn't have to cross the native->JVM boundary at all, so it's quicker than using e.g. a byte[] array or a normal ByteBuffer, where the data would have to cross that boundary twice in the copy process.

提交回复
热议问题