当前位置:网站首页>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 .
边栏推荐
- 物联网毕设 --(STM32f407连接云平台检测数据)
- MySQL functions and related cases and exercises
- Stack application (balancer)
- Spark practice 1: build spark operation environment in single node local mode
- Go language web development series 29: Gin framework uses gin contrib / sessions library to manage sessions (based on cookies)
- json序列化时案例总结
- Sequence table (implemented in C language)
- 掌握Cypress命令行选项,是真正掌握Cypress的基础
- AI scores 81 in high scores. Netizens: AI model can't avoid "internal examination"!
- Flutter dynamic | fair 2.5.0 new version features
猜你喜欢

【电脑插入U盘或者内存卡显示无法格式化FAT32如何解决】
![[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

AI 考高数得分 81,网友:AI 模型也免不了“内卷”!

Mastering the cypress command line options is the basis for truly mastering cypress

Complete deep neural network CNN training with tensorflow to complete picture recognition case 2

研发团队资源成本优化实践

CVPR 2022 | 美团技术团队精选6篇优秀论文解读

The shortage of graphics cards finally came to an end: 3070ti for more than 4000 yuan, 2000 yuan cheaper than the original price, and 3090ti

刚毕业的欧洲大学生,就能拿到美国互联网大厂 Offer?

Flutter动态化 | Fair 2.5.0 新版本特性
随机推荐
Bidirectional linked list (we only need to pay attention to insert and delete functions)
Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
Setting up remote links to MySQL on Linux
Libuv Library - Design Overview (Chinese version)
Screenshot of the operation steps of upload labs level 4-level 9
Kivy tutorial how to automatically load kV files
Sequence table (implemented in C language)
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu
Complete deep neural network CNN training with tensorflow to complete picture recognition case 2
Anan's doubts
Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
SQL Injection (POST/Search)
Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
Error running 'application' in idea running: the solution of command line is too long
Stack application (balancer)
Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock
掌握Cypress命令行选项,是真正掌握Cypress的基础
Universal dividend source code, supports the dividend of any B on the BSC
Asp. Net core1.1 without project JSON, so as to generate cross platform packages