当前位置:网站首页>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 .
边栏推荐
- [redis] cache warm-up, cache avalanche and cache breakdown
- [机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
- SQL Injection (POST/Search)
- Software testing is so hard to find, only outsourcing offers, should I go?
- Golang — template
- 106. How to improve the readability of SAP ui5 application routing URL
- Typeerror resolved: argument 'parser' has incorrect type (expected lxml.etree.\u baseparser, got type)
- 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
- [technology development-24]: characteristics of existing IOT communication technology
- Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
猜你喜欢
[技术发展-24]:现有物联网通信技术特点
8 Queen question
MySQL functions and related cases and exercises
SQL Injection (GET/Search)
There is nothing new under the sun. Can the meta universe go higher?
[bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]
Brief analysis of tensorboard visual processing cases
[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered
Introduction to the implementation principle of rxjs observable filter operator
随机推荐
Open PHP error prompt under Ubuntu 14.04
Kivy教程之 如何通过字符串方式载入kv文件设计界面(教程含源码)
Kivy教程之 如何自动载入kv文件
Introduction to the implementation principle of rxjs observable filter operator
[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Golang - command line tool Cobra
Can newly graduated European college students get an offer from a major Internet company in the United States?
The solution of Chinese font garbled code in keil5
[技术发展-24]:现有物联网通信技术特点
Box layout of Kivy tutorial BoxLayout arranges sub items in vertical or horizontal boxes (tutorial includes source code)
Red hat satellite 6: better management of servers and clouds
Kivy教程之 盒子布局 BoxLayout将子项排列在垂直或水平框中(教程含源码)
Leetcode-1175.Prime Arrangements
Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
Unity Render Streaming通过Js与Unity自定义通讯
MySQL 数据处理值增删改
KEIL5出现中文字体乱码的解决方法
父亲和篮球
The reasons why there are so many programming languages in programming internal skills