public class SimpleByteBufferPool implements ByteBufferPool
A pool for byte buffers, similar to connection pools. Avoids frequent re-allocation.
Example:
// obtain a buffer
val buffer = bufferPool.get(1024 * 50 /* 50 KiB */)
// use the buffer
buffer.write(someData)
writeData(buffer)
// return it
bufferPool.put(buffer)ByteBufferPool.CompanionCompanion| Constructor and Description |
|---|
SimpleByteBufferPool(boolean allocateDirect,
int maxSpareBuffers)
A pool for byte buffers, similar to connection pools.
Avoids frequent re-allocation.
|
SimpleByteBufferPool(boolean allocateDirect)
A pool for byte buffers, similar to connection pools.
Avoids frequent re-allocation.
|
SimpleByteBufferPool()
A pool for byte buffers, similar to connection pools.
Avoids frequent re-allocation.
|
| Modifier and Type | Method and Description |
|---|---|
void |
free(java.nio.ByteBuffer buffer)
Returns this buffer to the pool. User code must not hold any
references to the given buffer after this method returns.
|
boolean |
getAllocateDirect()
Whether to allocate memory off-heap.
|
int |
getMaxSpareBuffers()
Maximum number of spare buffers
|
java.nio.ByteBuffer |
pop(int minSize)
Returns a buffer that has at least the given amount of bytes
of available space. If no such buffer is currently free, one
will be allocated.
|
free, poppublic SimpleByteBufferPool(boolean allocateDirect,
int maxSpareBuffers)
A pool for byte buffers, similar to connection pools. Avoids frequent re-allocation.
Example:
// obtain a buffer
val buffer = bufferPool.get(1024 * 50 /* 50 KiB */)
// use the buffer
buffer.write(someData)
writeData(buffer)
// return it
bufferPool.put(buffer)allocateDirect - Whether to allocate memory off-heap.maxSpareBuffers - Maximum number of spare bufferspublic SimpleByteBufferPool(boolean allocateDirect)
A pool for byte buffers, similar to connection pools. Avoids frequent re-allocation.
Example:
// obtain a buffer
val buffer = bufferPool.get(1024 * 50 /* 50 KiB */)
// use the buffer
buffer.write(someData)
writeData(buffer)
// return it
bufferPool.put(buffer)allocateDirect - Whether to allocate memory off-heap.public SimpleByteBufferPool()
A pool for byte buffers, similar to connection pools. Avoids frequent re-allocation.
Example:
// obtain a buffer
val buffer = bufferPool.get(1024 * 50 /* 50 KiB */)
// use the buffer
buffer.write(someData)
writeData(buffer)
// return it
bufferPool.put(buffer)public java.nio.ByteBuffer pop(int minSize)
Returns a buffer that has at least the given amount of bytes of available space. If no such buffer is currently free, one will be allocated.
public void free(java.nio.ByteBuffer buffer)
Returns this buffer to the pool. User code must not hold any references to the given buffer after this method returns.
public boolean getAllocateDirect()
Whether to allocate memory off-heap.
public int getMaxSpareBuffers()
Maximum number of spare buffers