use of io.netty.buffer.ByteBuf in project netty by netty.
the class ByteBufAllocatorBenchmark method pooledDirectAllocAndFree.
@Benchmark
public void pooledDirectAllocAndFree() {
int idx = rand.nextInt(pooledDirectBuffers.length);
ByteBuf oldBuf = pooledDirectBuffers[idx];
if (oldBuf != null) {
oldBuf.release();
}
pooledDirectBuffers[idx] = pooledAllocator.directBuffer(size);
}
use of io.netty.buffer.ByteBuf in project netty by netty.
the class ByteBufAllocatorBenchmark method unpooledDirectAllocAndFree.
@Benchmark
public void unpooledDirectAllocAndFree() {
int idx = rand.nextInt(unpooledDirectBuffers.length);
ByteBuf oldBuf = unpooledDirectBuffers[idx];
if (oldBuf != null) {
oldBuf.release();
}
unpooledDirectBuffers[idx] = unpooledAllocator.directBuffer(size);
}
use of io.netty.buffer.ByteBuf in project netty by netty.
the class ByteBufAllocatorBenchmark method defaultPooledHeapAllocAndFree.
@Benchmark
public void defaultPooledHeapAllocAndFree() {
int idx = rand.nextInt(defaultPooledHeapBuffers.length);
ByteBuf oldBuf = defaultPooledHeapBuffers[idx];
if (oldBuf != null) {
oldBuf.release();
}
defaultPooledHeapBuffers[idx] = PooledByteBufAllocator.DEFAULT.heapBuffer(size);
}
use of io.netty.buffer.ByteBuf in project netty by netty.
the class SlicedByteBufBenchmark method setup.
@Setup
public void setup() {
// Use buffer sizes that will also allow to write UTF-8 without grow the buffer
ByteBuf buffer = Unpooled.buffer(512).retain();
slicedByteBuf = buffer.slice(0, 256);
slicedAbstractByteBuf = buffer.slice(0, 256);
if (slicedByteBuf.getClass() == slicedAbstractByteBuf.getClass()) {
throw new IllegalStateException();
}
StringBuilder asciiSequence = new StringBuilder(128);
for (int i = 0; i < 128; i++) {
asciiSequence.append('a');
}
ascii = asciiSequence.toString();
}
use of io.netty.buffer.ByteBuf in project netty by netty.
the class EmbeddedChannelWriteAccumulatingHandlerContext method writeAndFlush.
@Override
public final ChannelFuture writeAndFlush(Object msg, ChannelPromise promise) {
try {
if (msg instanceof ByteBuf) {
ByteBuf buf = (ByteBuf) msg;
if (cumulation == null) {
cumulation = buf;
} else {
cumulation = cumulator.cumulate(alloc(), cumulation, buf);
}
promise.setSuccess();
} else {
channel().writeAndFlush(msg, promise);
}
} catch (Exception e) {
promise.setFailure(e);
handleException(e);
}
return promise;
}
Aggregations