当前位置:网站首页>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的位置写数据, 这样防止了数据的丢失.
边栏推荐
- How to solve the three major problems of bank data collection, data supplementary recording and index management?
- The most effective seven performance testing techniques of software testing techniques
- After the large pixel panorama is completed, what are the promotion methods?
- DEJA_VU3D - Cesium功能集 之 058-高德地图纠偏
- Mathematics - Properties of Summation Symbols
- UE4 为子弹蓝图添加声音和粒子效果
- 大佬们,我注意到mysql cdc connector有参数scan.incremental.sna
- token、jwt、oauth2、session解析
- UE4 后期处理体积 (角色受到伤害场景颜色变淡案例)
- 【树莓派】树莓派调光
猜你喜欢

After the large pixel panorama is completed, what are the promotion methods?

Web3.0 Dapps——通往未来金融世界的道路

UE4 后期处理体积 (角色受到伤害场景颜色变淡案例)
![[CISCN2019 华东南赛区]Web11](/img/15/843334fec0a5cc8cfaba92aab938db.png)
[CISCN2019 华东南赛区]Web11
![Spark Basics [Introduction, Getting Started with WordCount Cases]](/img/90/ebe887db0f8c36895691dea05f62cf.png)
Spark Basics [Introduction, Getting Started with WordCount Cases]

MySql index learning and use; (I think it is detailed enough)

Solana NFT开发指南

Defect detection (image processing part)

将故事写成我们

Industry Status?Why do Internet companies prefer to spend 20k to recruit people rather than raise their salary to retain old employees~
随机推荐
事件解析树Drain3使用方法和解释
队列题目:最近的请求次数
Detailed and comprehensive postman interface testing practical tutorial
The second council meeting of the Dragon Lizard Community was successfully held!Director general election, 4 special consultants joined
不看后悔,appium自动化环境完美搭建
【8.3】代码源 - 【喵 ~ 喵 ~ 喵~】【树】【与】
MRTK3 develops Hololens application - gesture drag, rotate, zoom object implementation
多御安全浏览器 V10.8.3.1 版正式发布,优化多项内容
【8.2】代码源 - 【货币系统】【硬币】【新年的问题(数据加强版)】【三段式】
[论文笔记] MapReduce: Simplified Data Processing on Large Clusters
Confessing the era of digital transformation, Speed Cloud engraves a new starting point for value
UE4 在游戏运行时更改变量 (通过鼠标滑轮来更改第一人称角色的最大行走速度)
cross domain solution
Ffmpeg - sources analysis
The sword refers to Offer--find the repeated numbers in the array (three solutions)
UE4 通过与其它Actor互动开门
How to wrap markdown - md file
[CISCN2019 华东南赛区]Web11
MySql的索引学习和使用;(本人觉得足够详细)
多列属性column元素的可见性:display、visibility、opacity、垂直对齐方式:vertical-align、z-index 越大越显示在上层