@Override public ByteBuffer allocateDirectBuffer(final int size) { final int requiredCapacity = align(size, DEFAULT_CAPACITY_ALIGNMENT); final ByteBuffer byteBuffer = ByteBuffer.allocateDirect(requiredCapacity); byteBuffer.limit(size); return byteBuffer; }
@Override public ByteBuffer allocateDirectBuffer(final int size) { final int requiredCapacity = align(size, DEFAULT_CAPACITY_ALIGNMENT); final ByteBuffer byteBuffer = ByteBuffer.allocateDirect(requiredCapacity); byteBuffer.limit(size); return byteBuffer; }
@Override public ByteBuffer newBuffer(final int size) { if (!this.bufferPooling) { return allocateDirectBuffer(size); } else { final int requiredCapacity = align(size, DEFAULT_CAPACITY_ALIGNMENT); ByteBuffer byteBuffer = bytesPool.get(); if (byteBuffer == null || requiredCapacity > byteBuffer.capacity()) { //do not free the old one (if any) until the new one will be released into the pool! byteBuffer = ByteBuffer.allocateDirect(requiredCapacity); } else { bytesPool.set(null); PlatformDependent.setMemory(PlatformDependent.directBufferAddress(byteBuffer), size, (byte) 0); byteBuffer.clear(); } byteBuffer.limit(size); return byteBuffer; } }
@Override public ByteBuffer newBuffer(final int size) { if (!this.bufferPooling) { return allocateDirectBuffer(size); } else { final int requiredCapacity = align(size, DEFAULT_CAPACITY_ALIGNMENT); ByteBuffer byteBuffer = bytesPool.get(); if (byteBuffer == null || requiredCapacity > byteBuffer.capacity()) { //do not free the old one (if any) until the new one will be released into the pool! byteBuffer = ByteBuffer.allocateDirect(requiredCapacity); } else { bytesPool.set(null); PlatformDependent.setMemory(PlatformDependent.directBufferAddress(byteBuffer), size, (byte) 0); byteBuffer.clear(); } byteBuffer.limit(size); return byteBuffer; } }