NOTE
2.93 使用
本文通过代码示例记录 Netty 的内存相关使用方式,作为继续阅读分配器实现的实践入口。
这是历史学习笔记,可能存在过时或不完整的理解。
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规格内存分配 会变成大于等于16的整数倍的数:这里254 会规格化为256
ByteBuf byteBuf = alloc.directBuffer(254);
//读写bytebuf
byteBuf.writeInt(126);
System.out.println(byteBuf.readInt());
//很重要,内存释放
byteBuf.release();
}
}
拖动可平移,滚轮缩放,点击节点可展开或折叠。大型导图默认折叠较深层级,可点击节点继续展开。
讨论
使用 GitHub 账号参与讨论,评论会保存在 GitHub Issues 中。在 GitHub 查看