Growing ByteBuffer

前端 未结 11 1138
温柔的废话
温柔的废话 2021-01-31 14:21

Has anyone has ever seen an implementation of java.nio.ByteBuffer that will grow dynamically if a putX() call overruns the capacity?

The reason I want to do it this way

11条回答
  •  悲&欢浪女
    2021-01-31 15:10

    Indeed, auto-extending buffers are so much more intuitive to work with. If you can afford the performance luxury of reallocation, why wouldn't you!?

    Netty's ByteBuf gives you exactly this. It's like they've taken java.nio's ByteBuffer and scraped away the edges, making it much easier to use.

    Furthermore, it's on Maven in an independent netty-buffer package so you don't need to include the full Netty suite to use.

提交回复
热议问题