NOTE
Usage
Code examples record Netty memory-related usage and provide a practical starting point for reading allocator implementations.
This is a historical learning note and may contain outdated or incomplete understanding.
package com.example.demo;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.PooledByteBufAllocator;
/**
* @description:
* @author: <AUTHOR>
* @create: 2019-12-13 19:34
**/
public class ByteBufDemo
{
public static void main(String[] args)
{
ByteBufAllocator alloc = PooledByteBufAllocator.DEFAULT;
// tiny-size memory allocation is normalized to an integer multiple of 16
// that is greater than or equal to the requested size:
// 254 is normalized to 256 here.
ByteBuf byteBuf = alloc.directBuffer(254);
// Read and write ByteBuf.
byteBuf.writeInt(126);
System.out.println(byteBuf.readInt());
// Very important: release the memory.
byteBuf.release();
}
}
Drag to pan, scroll to zoom, and click a node to expand or collapse it. Large maps start with deeper levels collapsed; click nodes to expand them.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub