当前位置:网站首页>Use and design of Muduo buffer class
Use and design of Muduo buffer class
2022-07-03 13:48:00 【yolo_ yyh】
Catalog
(2) towards Buffer Write in 200 byte
(3) from Buffer Read in 50 byte
(4) towards Buffer Write in 200 byte
(5) from Buffer Read in 350 byte
muduo It's for Chen Shuo's personal use C++ Developed a network library , The code is of great learning value , The summary comes from books 《Linux Multithreaded server-side programming 》, Also written by Chen Shuo , Can cooperate with github Use code together .
muduo github website :https://github.com/chenshuo/muduo
One 、Buffer Data structure of

muduo Designed buffer As a buffer for sending and receiving data ,Buffer Inside is a std::vector<char>, It's a piece of continuous memory , Two of them index,readIndex and writeIndex hold vector The content of is divided into three parts :prependable、readable、writeable

prependable = readIndex;
readable = writeIndex-readIndex
writable = size() - writeIndex
Two 、Buffer The operation of
Suppose the sender sends two messages , The lengths are 50 Byte and 350 byte , The receiver receives the data twice , Every time 200 byte , Then subcontract , Call back the customer code twice , among readIndex and writeIndex Is initialized to 8,size() The initial value is 1032, This process Buffer The data structure changes of are as follows :
(1) Initial value

(2) towards Buffer Write in 200 byte

(3) from Buffer Read in 50 byte

(4) towards Buffer Write in 200 byte

(5) from Buffer Read in 350 byte

At this time, all data has been read ,readIndex and writeIndex It will return to its original position for reuse .
muduo Buffer It also supports internal mobility , When readIndex More backward , Leave a huge prependable When space , If you write at this time and writeable Space is not enough ,Buffer Memory will not be reallocated , Instead, move the existing data to the front , Vacate writable Space .
边栏推荐
- Resource Cost Optimization Practice of R & D team
- 106. How to improve the readability of SAP ui5 application routing URL
- [机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
- JS convert pseudo array to array
- 8 Queen question
- 【556. 下一个更大元素 III】
- 静态链表(数组的下标代替指针)
- Unity render streaming communicates with unity through JS
- 3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
- JS 将伪数组转换成数组
猜你喜欢

Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu

Unity embeddedbrowser browser plug-in event communication

Error running 'application' in idea running: the solution of command line is too long

User and group command exercises
![[technology development-24]: characteristics of existing IOT communication technology](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[technology development-24]: characteristics of existing IOT communication technology

PhpMyAdmin stage file contains analysis traceability
![[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion](/img/3b/28327bbf5eb19254f03500a41e2adb.jpg)
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion

Halcon combined with C # to detect surface defects -- Halcon routine autobahn

Universal dividend source code, supports the dividend of any B on the BSC

CVPR 2022 | interpretation of 6 excellent papers selected by meituan technical team
随机推荐
Kivy tutorial how to automatically load kV files
Complete deep neural network CNN training with tensorflow to complete picture recognition case 2
PhpMyAdmin stage file contains analysis traceability
Flutter动态化 | Fair 2.5.0 新版本特性
php 迷宫游戏
[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]
记录关于银行回调post请求405 问题
Flutter dynamic | fair 2.5.0 new version features
网上开户哪家证券公司佣金最低,我要开户,网上客户经理开户安全吗
Libuv库 - 设计概述(中文版)
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
JS convert pseudo array to array
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Spark practice 1: build spark operation environment in single node local mode
Sequence table (implemented in C language)
Red hat satellite 6: better management of servers and clouds
Which securities company has the lowest Commission for opening an account online? I want to open an account. Is it safe for the online account manager to open an account
研发团队资源成本优化实践
The solution of Chinese font garbled code in keil5
Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station