Growing ByteBuffer

前端 未结 11 1143
温柔的废话
温柔的废话 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:19

    Another option is to use direct memory with a large buffer. This consumes virtual memory but only uses as much physical memory as you use (by page which is typically 4K)

    So if you allocate a buffer of 1 MB, it comsumes 1 MB of virtual memory, but the only OS gives physical pages to the application which is actually uses.

    The effect is you see your application using alot of virtual memory but a relatively small amount of resident memory.

提交回复
热议问题