当前位置:网站首页>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的位置写数据, 这样防止了数据的丢失.
边栏推荐
- Android Practical Development - Kotlin Tutorial (Introduction - Login Function Implementation 3.3)
- You may use special comments to disable some warnings. Three ways to report errors
- JeeSite新建报表
- Why is the pca component not associated
- Web3.0 Dapps - the road to the future financial world
- ffmpeg 枚举decoders, encoders 分析
- Dameng 8 database export and import
- 905. 区间选点
- UE4 更改组件变量 (以修改第一人称角色模板的最大行走速度和跳跃高度为例)
- 日志导致线程Block的这些坑,你不得不防
猜你喜欢

Initial solution of the structure

2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer appears after successful startup of presto

冰蝎V4.0攻击来袭,安全狗产品可全面检测

Why is the pca component not associated

21 Days Learning Challenge (2) Use of Graphical Device Trees

markdown如何换行——md文件

将故事写成我们

Use CH341A to program external Flash (W25Q16JV)

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

Kubernetes 网络入门
随机推荐
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
Leading the highland of digital medicine, Zhongshan Hospital explores to create a "new paradigm" for future hospitals
[Paper Notes] MapReduce: Simplified Data Processing on Large Clusters
十五. 实战——mysql建库建表 字符集 和 排序规则
Static method to get configuration file data
Common open source databases under Linux, how many do you know?
Hard power or soft power, which is more important to testers?
达梦8数据库导出导入
Acid (ACID) Base (BASE) Principles for Database Design
[Solved] Unity Coroutine coroutine is not executed effectively
多列属性column元素的可见性:display、visibility、opacity、垂直对齐方式:vertical-align、z-index 越大越显示在上层
UE4 第一人称角色模板 添加生命值和调试伤害
Redis key basic commands
ffmpeg -sources分析
冰蝎V4.0攻击来袭,安全狗产品可全面检测
2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer appears after successful startup of presto
多御安全浏览器新版下载 | 功能优秀性能出众
sql怎么找字段里所有数据为空的字段
pyqt5 + socket 实现客户端A经socket服务器中转后主动向客户端B发送文件
[Filter tracking] based on matlab unscented Kalman filter inertial navigation + DVL combined navigation [including Matlab source code 2019]