当前位置:网站首页>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 .
边栏推荐
- The principle of human voice transformer
- Open PHP error prompt under Ubuntu 14.04
- Kivy tutorial how to load kV file design interface by string (tutorial includes source code)
- MySQL 数据处理值增删改
- Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
- [how to earn a million passive income]
- windos 创建cordova 提示 因为在此系统上禁止运行脚本
- [quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
- [understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered
- mysql中的字段问题
猜你喜欢
Mycms we media mall v3.4.1 release, user manual update
Golang - command line tool Cobra
The solution of Chinese font garbled code in keil5
AI scores 81 in high scores. Netizens: AI model can't avoid "internal examination"!
HALCON联合C#检测表面缺陷——HALCON例程autobahn
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
PhpMyAdmin stage file contains analysis traceability
Road construction issues
KEIL5出现中文字体乱码的解决方法
Richview trvstyle liststyle list style (bullet number)
随机推荐
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
Resource Cost Optimization Practice of R & D team
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes
网上开户哪家证券公司佣金最低,我要开户,网上客户经理开户安全吗
Kivy tutorial how to load kV file design interface by string (tutorial includes source code)
Typeerror resolved: argument 'parser' has incorrect type (expected lxml.etree.\u baseparser, got type)
Software testing is so hard to find, only outsourcing offers, should I go?
使用tensorflow进行完整的DNN深度神经网络CNN训练完成图片识别案例
Mastering the cypress command line options is the basis for truly mastering cypress
[technology development-24]: characteristics of existing IOT communication technology
Father and basketball
SVN添加文件时的错误处理:…\conf\svnserve.conf:12: Option expected
IBEM 数学公式检测数据集
常见的几种最优化方法Matlab原理和深度分析
Screenshot of the operation steps of upload labs level 4-level 9
使用Tensorflow进行完整的深度神经网络CNN训练完成图片识别案例2
Field problems in MySQL
研发团队资源成本优化实践
untiy世界边缘的物体阴影闪动,靠近远点的物体阴影正常
TensorBoard可视化处理案例简析