提交 ec5bedb4 authored 作者: Thomas Mueller Graf's avatar Thomas Mueller Graf

Allow to create smaller write buffers

上级 bbf44d45
...@@ -12,6 +12,9 @@ import java.nio.ByteBuffer; ...@@ -12,6 +12,9 @@ import java.nio.ByteBuffer;
*/ */
public class WriteBuffer { public class WriteBuffer {
/**
* The maximum size of the buffer in order to be re-used after a clear operation.
*/
private static final int MAX_REUSE_CAPACITY = 4 * 1024 * 1024; private static final int MAX_REUSE_CAPACITY = 4 * 1024 * 1024;
/** /**
...@@ -19,9 +22,24 @@ public class WriteBuffer { ...@@ -19,9 +22,24 @@ public class WriteBuffer {
*/ */
private static final int MIN_GROW = 1024 * 1024; private static final int MIN_GROW = 1024 * 1024;
private ByteBuffer reuse = ByteBuffer.allocate(MIN_GROW); /**
* The buffer that is used after a clear operation.
*/
private ByteBuffer reuse;
/**
* The current buffer (may be replaced if it is too small).
*/
private ByteBuffer buff;
private ByteBuffer buff = reuse; public WriteBuffer(int initialSize) {
reuse = ByteBuffer.allocate(initialSize);
buff = reuse;
}
public WriteBuffer() {
this(MIN_GROW);
}
/** /**
* Write a variable size integer. * Write a variable size integer.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论