当前位置:网站首页>bytebuffer internal structure
bytebuffer internal structure
2022-08-05 03:59:00 【java continuous practice】
ByteBuffer internal structure
ByteBuffer important properties
- capacity: capacity. How much data can fit in the bytebuffer
- position: Read and write pointer. Index subscript
- limit: limit for reading and writing
In the beginning, the post is at the starting position, limit is the limit size of writing,
In write mode, 4 values are written, position moves 4 positions, limit is the capacity to write.
After calling flip() method, turn on read mode, postion starts reading from 0 again, limit moves from capacity position to topOne step to read the position of the data, because the write only writes to the position of d, no need to read the position of the capacity.
The state after reading 4 bytes, after calling the get() method, the position moves to the limit position, and the reading is completed.
After calling clear method, switch to write mode and position returns to 0, limit returns to the position of capacity, which means that data of capacity size can be written.
compact method: For some reason, the data must be written before the data is read. The following original data contains four bytes of abcd data. After reading ab, it is necessary to write the data and call compact.The method is to start writing data from d, instead of writing data from 0, which prevents data loss.
边栏推荐
猜你喜欢

商业智能BI业务分析思维:现金流量风控分析(一)营运资金风险

bytebuffer 使用demo

Initial solution of the structure

银行数据采集,数据补录与指标管理3大问题如何解决?

Getting Started with Kubernetes Networking

Use Unity to publish APP to Hololens2 without pit tutorial

This year's Qixi Festival, "love vegetables" are more loving than gifts

Hard power or soft power, which is more important to testers?

Shell script: for loop and the while loop
![[BSidesCF 2019]Kookie](/img/29/19e7c244feb86b37ab32a53aa11f25.png)
[BSidesCF 2019]Kookie
随机推荐
UE4 opens door via interaction (keyboard key)
ffmpeg enumeration decoders, encoders analysis
Web3.0 Dapps - the road to the future financial world
UE4 为子弹蓝图添加声音和粒子效果
35岁的软件测试工程师,月薪不足2W,辞职又怕找不到工作,该何去何从?
Swing有几种常用的事件处理方式?如何监听事件?
2022 Hangzhou Electric Multi-School 1st Game
用Unity发布APP到Hololens2无坑教程
21 Days Learning Challenge (2) Use of Graphical Device Trees
ffmpeg 像素格式基础知识
七夕节代码表白
Developing Hololens encountered The type or namespace name 'HandMeshVertex' could not be found..
关于#SQL#的迭代、父子结构查询问题,如何解决?
UE4 第一人称角色模板 添加冲刺(加速)功能
Getting Started with Kubernetes Networking
【树莓派】树莓派调光
There are several common event handling methods in Swing?How to listen for events?
Solana NFT开发指南
多御安全浏览器新版下载 | 功能优秀性能出众
The most comprehensive exam questions for software testing engineers in 2022