当前位置:网站首页>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 .
边栏推荐
- Setting up remote links to MySQL on Linux
- Resolved (error in viewing data information in machine learning) attributeerror: target_ names
- SQL Injection (POST/Select)
- Mastering the cypress command line options is the basis for truly mastering cypress
- Flutter dynamic | fair 2.5.0 new version features
- Logback log sorting
- Multi table query of MySQL - multi table relationship and related exercises
- [understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered
- Asp. Net core1.1 without project JSON, so as to generate cross platform packages
- Several common optimization methods matlab principle and depth analysis
猜你喜欢

RichView TRVStyle ListStyle 列表样式(项目符号编号)

The principle of human voice transformer

Go language unit test 4: go language uses gomonkey to test functions or methods

Introduction to the implementation principle of rxjs observable filter operator

Several common optimization methods matlab principle and depth analysis

User and group command exercises

Screenshot of the operation steps of upload labs level 4-level 9
![[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

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

挡不住了,国产芯片再度突进,部分环节已进到4nm
随机推荐
[技术发展-24]:现有物联网通信技术特点
Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu
The reasons why there are so many programming languages in programming internal skills
Students who do not understand the code can also send their own token, which is easy to learn BSC
PhpMyAdmin stage file contains analysis traceability
Red hat satellite 6: better management of servers and clouds
Box layout of Kivy tutorial BoxLayout arranges sub items in vertical or horizontal boxes (tutorial includes source code)
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
Complete deep neural network CNN training with tensorflow to complete picture recognition case 2
Road construction issues
Universal dividend source code, supports the dividend of any B on the BSC
[today in history] July 3: ergonomic standards act; The birth of pioneers in the field of consumer electronics; Ubisoft releases uplay
MySQL installation, uninstallation, initial password setting and general commands of Linux
Brief analysis of tensorboard visual processing cases
Asp. Net core1.1 without project JSON, so as to generate cross platform packages
研发团队资源成本优化实践
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
Software testing is so hard to find, only outsourcing offers, should I go?
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