当前位置:网站首页>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的位置写数据, 这样防止了数据的丢失.
边栏推荐
- sql怎么找字段里所有数据为空的字段
- Queue Topic: Recent Requests
- MySql的索引学习和使用;(本人觉得足够详细)
- 关于#SQL#的迭代、父子结构查询问题,如何解决?
- Leading the highland of digital medicine, Zhongshan Hospital explores to create a "new paradigm" for future hospitals
- Dive into how it works together by simulating Vite
- iMedicalLIS listener (2)
- Android实战开发-Kotlin教程(入门篇-登录功能实现 3.3)
- 大佬们,我注意到mysql cdc connector有参数scan.incremental.sna
- DEJA_VU3D - Cesium功能集 之 056-智图Arcgis地图纠偏
猜你喜欢
Industry Status?Why do Internet companies prefer to spend 20k to recruit people rather than raise their salary to retain old employees~
新人如何入门和学习软件测试?
YYGH-13-Customer Service Center
Based on holding YOLOv5 custom implementation of FacePose YOLO structure interpretation, YOLO data format conversion, YOLO process modification"
Static method to get configuration file data
今年七夕,「情蔬」比礼物更有爱
Use CH341A to program external Flash (W25Q16JV)
炎炎夏日教你利用小米智能家居配件+树莓派4接入Apple HomeKit
Ali's local life's single-quarter revenue is 10.6 billion, Da Wenyu's revenue is 7.2 billion, and Cainiao's revenue is 12.1 billion
How to wrap markdown - md file
随机推荐
UE4 通过与其它Actor互动开门
ffmpeg -sources分析
There are several common event handling methods in Swing?How to listen for events?
新人如何入门和学习软件测试?
将故事写成我们
【测量学】速成汇总——摘录高数帮
Android实战开发-Kotlin教程(入门篇-登录功能实现 3.3)
UE4 opens door via interaction (keyboard key)
[CISCN2019 华东南赛区]Web11
多御安全浏览器新版下载 | 功能优秀性能出众
Summary of common methods of arrays
十五. 实战——mysql建库建表 字符集 和 排序规则
Call Alibaba Cloud oss and sms services
第一次性能测试实践,有“亿”点点紧张
YYGH-13-Customer Service Center
Ice Scorpion V4.0 attack, security dog products can be fully detected
关于#SQL#的迭代、父子结构查询问题,如何解决?
银行数据采集,数据补录与指标管理3大问题如何解决?
Event parse tree Drain3 usage and explanation
JeeSite新建报表