当前位置:网站首页>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 更改组件变量 (以修改第一人称角色模板的最大行走速度和跳跃高度为例)
- 2022.8.4-----leetcode.1403
- Leading the highland of digital medicine, Zhongshan Hospital explores to create a "new paradigm" for future hospitals
- Android 面试题——如何徒手写一个非阻塞线程安全队列 ConcurrentLinkedQueue?
- Redis1: Introduction to Redis, basic features of Redis, relational database, non-relational database, database development stage
- 2022 High-level installation, maintenance, and removal of exam questions mock exam question bank and online mock exam
- leetcode-每日一题1403. 非递增顺序的最小子序列(贪心)
- Ice Scorpion V4.0 attack, security dog products can be fully detected
- 达梦8数据库导出导入
- [Software testing] unittest framework for automated testing
猜你喜欢

UE4 opens doors with overlapping events
![[Software testing] unittest framework for automated testing](/img/80/caedd5cf6dd61c9d75475866613cac.png)
[Software testing] unittest framework for automated testing

阿里本地生活单季营收106亿,大文娱营收72亿,菜鸟营收121亿

markdown如何换行——md文件

Developing Hololens encountered The type or namespace name 'HandMeshVertex' could not be found..

七夕节代码表白

Leading the highland of digital medicine, Zhongshan Hospital explores to create a "new paradigm" for future hospitals

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

The test salary is so high?20K just graduated

开发Hololens遇到The type or namespace name ‘HandMeshVertex‘ could not be found..
随机推荐
Solana NFT开发指南
DEJA_VU3D - Cesium功能集 之 058-高德地图纠偏
token, jwt, oauth2, session parsing
DEJA_VU3D - Cesium功能集 之 056-智图Arcgis地图纠偏
905. 区间选点
【8.1】代码源 - 【第二大数字和】【石子游戏 III】【平衡二叉树】
DEJA_VU3D - Cesium功能集 之 059-腾讯地图纠偏
UE4 第一人称角色模板 添加生命值和调试伤害
Dive into how it works together by simulating Vite
Initial solution of the structure
35岁的软件测试工程师,月薪不足2W,辞职又怕找不到工作,该何去何从?
ffmpeg -sources分析
leetcode-每日一题1403. 非递增顺序的最小子序列(贪心)
How to find all fields with empty data in sql
[论文笔记] MapReduce: Simplified Data Processing on Large Clusters
token、jwt、oauth2、session解析
UE4 通过重叠事件开启门
七夕节代码表白
大佬们,我注意到mysql cdc connector有参数scan.incremental.sna
MRTK3 develops Hololens application - gesture drag, rotate, zoom object implementation