当前位置:网站首页>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的位置写数据, 这样防止了数据的丢失.
边栏推荐
- Swing有几种常用的事件处理方式?如何监听事件?
- Spark Basics [Introduction, Getting Started with WordCount Cases]
- UE4 后期处理体积 (角色受到伤害场景颜色变淡案例)
- ffmpeg -sources分析
- 【树莓派】树莓派调光
- Android 面试题——如何徒手写一个非阻塞线程安全队列 ConcurrentLinkedQueue?
- YYGH-13-客服中心
- Redis1:Redis介绍、Redis基本特性、关系型数据库、非关系型数据库、数据库发展阶段
- Index Mysql in order to optimize paper 02 】 【 10 kinds of circumstances and the principle of failure
- iMedicalLIS listener (2)
猜你喜欢

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

Increasing leetcode - a daily topic 1403. The order of the boy sequence (greed)

UE4 第一人称角色模板 添加冲刺(加速)功能

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

UI自动化测试 App的WebView页面中,当搜索栏无搜索按钮时处理方法

21 Days Learning Challenge (2) Use of Graphical Device Trees
![[GYCTF2020]EasyThinking](/img/40/973411c69d1e4766d22f6a4a7c7c01.png)
[GYCTF2020]EasyThinking

iMedicalLIS监听程序(2)

Getting Started with Kubernetes Networking

日志导致线程Block的这些坑,你不得不防
随机推荐
Walter talked little knowledge | "remote passthrough" that something
Hard power or soft power, which is more important to testers?
rpc-remote procedure call demo
达梦8数据库导出导入
Getting Started with Kubernetes Networking
UE4 更改组件变量 (以修改第一人称角色模板的最大行走速度和跳跃高度为例)
UE4 opens door via interaction (keyboard key)
What is the difference between SAP ERP and ORACLE ERP?
10 years of testing experience, worthless in the face of the biological age of 35
MRTK3 develops Hololens application - gesture drag, rotate, zoom object implementation
基于生长的棋盘格角点检测方法
Dive into how it works together by simulating Vite
Redis key基本命令
GC Gaode coordinate and Baidu coordinate conversion
XMjs cross-domain problem solving
关于#SQL#的迭代、父子结构查询问题,如何解决?
十五. 实战——mysql建库建表 字符集 和 排序规则
七夕节代码表白
How to discover a valuable GameFi?
leetcode-每日一题1403. 非递增顺序的最小子序列(贪心)