readerIndex ,读索引
writerIndex ,写索引
capacity ,当前容量
maxCapacity ,最大容量,当 writerIndex 写入超过 capacity 时,可自动扩容。每次扩容的大小,为 capacity 的 2 倍。当然,前提是不能超过 maxCapacity 大小
readerIndex <= writerIndex <= capacity <= maxCapacity
0~readerIndex ,废弃段 , 一般情况下可理解为已读的部分
readerIndex~writerIndex , 可读段, 可通过 #readXXX() 方法,顺序向下读取
writerIndex~capacity , 可写段, 可通过 #writeXXX() 方法,顺序向下写入
markReaderIndex .markWriterIndex
#markReaderIndex() 和 #markWriterIndex() 方法,分别标记读取和写入位置。#resetReaderIndex() 和 #resetWriterIndex() 方法,分别读取和写入位置到标记处。ByteBuf有8个最核心的子类实现
原文:https://www.cnblogs.com/luozhiyun/p/9962525.html