当前位置:网站首页>bytebuffer 内部结构
bytebuffer 内部结构
2022-08-05 03:53:00 【java持续实践】
ByteBuffer 内部结构
ByteBuffer 重要的属性
- capacity: 容量 . bytebuffer中能装多少数据
- position: 读写指针. 索引下标
- limit: 读写的限制
一开始postion 在起始位置, limit 为写入的限制大小,
写模式下, 写了4个值, position 进行了4个位置的移动, limit为写入的容量.
调用flip() 方法后, 开启读模式 , postion重新从0开始读, limit 从capacity的位置, 移动到上一步读取数据的位置, 因为写入只写入到d的位置, 无需读取到capacity的位置.
读取4个字节后的状态, 调用get() 方法后, position 移动位置到了limit的位置, 则读取完毕.
调用clear方法后, 切换到了写模式, position回到了0的位置, limit回到了capacity的位置, 代表可以写入capacity大小的数据.
compact方法: 由于某种原因, 没有读取完数据就要写数据, 如下原本数据中有abcd四个字节的数据, 读到ab了 , 就要写数据了, 调用compact方法, 则是从d后开始开始写数据, 而不是从0的位置写数据, 这样防止了数据的丢失.
边栏推荐
- UE4 为子弹蓝图添加声音和粒子效果
- The second council meeting of the Dragon Lizard Community was successfully held!Director general election, 4 special consultants joined
- The sword refers to Offer--find the repeated numbers in the array (three solutions)
- MySql的索引学习和使用;(本人觉得足够详细)
- Queue Topic: Recent Requests
- 2022 High-level installation, maintenance, and removal of exam questions mock exam question bank and online mock exam
- 运维监控系统之Open-Falcon
- SkiaSharp 之 WPF 自绘 粒子花园(案例版)
- 2022.8.4-----leetcode.1403
- presto启动成功后出现2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer
猜你喜欢

炎炎夏日教你利用小米智能家居配件+树莓派4接入Apple HomeKit

Index Mysql in order to optimize paper 02 】 【 10 kinds of circumstances and the principle of failure

UE4 在游戏运行时更改变量 (通过鼠标滑轮来更改第一人称角色的最大行走速度)

Ice Scorpion V4.0 attack, security dog products can be fully detected

UE4 通过与其它Actor互动开门

银行数据采集,数据补录与指标管理3大问题如何解决?

Defect detection (image processing part)

How to solve the three major problems of bank data collection, data supplementary recording and index management?

日志导致线程Block的这些坑,你不得不防

UE4 通过互动(键盘按键)开门
随机推荐
Open-Falcon of operation and maintenance monitoring system
多列属性column元素的可见性:display、visibility、opacity、垂直对齐方式:vertical-align、z-index 越大越显示在上层
The second council meeting of the Dragon Lizard Community was successfully held!Director general election, 4 special consultants joined
After the large pixel panorama is completed, what are the promotion methods?
shell脚本:for循环与while循环
UE4 opens doors with overlapping events
Fifteen. Actual combat - MySQL database building table character set and collation
pyqt5 + socket 实现客户端A经socket服务器中转后主动向客户端B发送文件
Detailed and comprehensive postman interface testing practical tutorial
Increasing leetcode - a daily topic 1403. The order of the boy sequence (greed)
Web3.0 Dapps——通往未来金融世界的道路
【8.4】代码源 - 【数学】【历法】【删库】【不朴素的数列(Bonus)】
MRTK3 develops Hololens application - gesture drag, rotate, zoom object implementation
What is the difference between SAP ERP and ORACLE ERP?
Android实战开发-Kotlin教程(入门篇-登录功能实现 3.3)
Event parse tree Drain3 usage and explanation
国学*周易*梅花易数 代码实现效果展示 - 梅花心易
2022 Hangzhou Electric Multi-School 1st Game
Haproxy搭建Web群集
【8.3】代码源 - 【喵 ~ 喵 ~ 喵~】【树】【与】