美文网首页
ByteBuffer.allocate()与allocateDi

ByteBuffer.allocate()与allocateDi

作者: 1nfinity | 来源:发表于2019-02-19 08:24 被阅读0次

    allocate()产生的是HeapByteBuffer的实例, 本质上是一个no direct buffer, allocateDirect()产生的是DirectByteBuffer的实例, 本质是一个direct buffer

    • 主要区别
      1. buffer的创建方式不同, no direct buffer还可以通过封装已存在的byte array来产生
      2. 执行IO操作时不同, no direct buffer会将自己复制到中间buffer中, 而direct buffer不会
      3. no direct buffer分配在heap上, 而direct buffer分配在直接内存中, 并不在JVM虚拟机中

    相关文章

      网友评论

          本文标题:ByteBuffer.allocate()与allocateDi

          本文链接:https://www.haomeiwen.com/subject/xhntyqtx.html