当前位置:网站首页>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的位置写数据, 这样防止了数据的丢失.
边栏推荐
- Dive into how it works together by simulating Vite
- UE4 第一人称角色模板 添加生命值和调试伤害
- public static <T> List<T> asList(T... a) 原型是怎么回事?
- How do newcomers get started and learn software testing?
- Developing Hololens encountered The type or namespace name 'HandMeshVertex' could not be found..
- 炎炎夏日教你利用小米智能家居配件+树莓派4接入Apple HomeKit
- [Paper Notes] MapReduce: Simplified Data Processing on Large Clusters
- What is the difference between SAP ERP and ORACLE ERP?
- Mathematics - Properties of Summation Symbols
- UE4 通过互动(键盘按键)开门
猜你喜欢

多列属性column元素的可见性:display、visibility、opacity、垂直对齐方式:vertical-align、z-index 越大越显示在上层

2022 High-level installation, maintenance, and removal of exam questions mock exam question bank and online mock exam

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

Event parse tree Drain3 usage and explanation

Acid (ACID) Base (BASE) Principles for Database Design

从企业的视角来看,数据中台到底意味着什么?

Open-Falcon of operation and maintenance monitoring system
![[GYCTF2020]EasyThinking](/img/40/973411c69d1e4766d22f6a4a7c7c01.png)
[GYCTF2020]EasyThinking
![Spark Basics [Introduction, Getting Started with WordCount Cases]](/img/90/ebe887db0f8c36895691dea05f62cf.png)
Spark Basics [Introduction, Getting Started with WordCount Cases]

新人如何入门和学习软件测试?
随机推荐
Confessing the era of digital transformation, Speed Cloud engraves a new starting point for value
Industry Status?Why do Internet companies prefer to spend 20k to recruit people rather than raise their salary to retain old employees~
开发Hololens遇到The type or namespace name ‘HandMeshVertex‘ could not be found..
MySql index learning and use; (I think it is detailed enough)
Walter talked little knowledge | "remote passthrough" that something
如何解决复杂的分销分账问题?
36-Jenkins-Job Migration
UE4 第一人称角色模板 添加冲刺(加速)功能
Detailed and comprehensive postman interface testing practical tutorial
调用阿里云oss和sms服务
token, jwt, oauth2, session parsing
How do newcomers get started and learn software testing?
There are several common event handling methods in Swing?How to listen for events?
ffmpeg enumeration decoders, encoders analysis
商业智能BI业务分析思维:现金流量风控分析(一)营运资金风险
UE4 为子弹蓝图添加声音和粒子效果
UE4 在游戏运行时更改变量 (通过鼠标滑轮来更改第一人称角色的最大行走速度)
Slapped in the face: there are so many testers in a certain department of byte
[论文笔记] MapReduce: Simplified Data Processing on Large Clusters
Developing Hololens encountered The type or namespace name 'HandMeshVertex' could not be found..