当前位置:网站首页>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 .
边栏推荐
- 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
- Disruptor -- a high concurrency and high performance queue framework for processing tens of millions of levels
- Depth and breadth first traversal of tree (regardless of binary tree)
- PHP maze game
- IBEM 数学公式检测数据集
- Ocean CMS vulnerability - search php
- 常见的几种最优化方法Matlab原理和深度分析
- IBEM mathematical formula detection data set
- Flutter动态化 | Fair 2.5.0 新版本特性
- Bidirectional linked list (we only need to pay attention to insert and delete functions)
猜你喜欢
![[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]](/img/95/09552d33d2a834af4d304129714775.png)
[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]

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

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

This math book, which has been written by senior ml researchers for 7 years, is available in free electronic version

常见的几种最优化方法Matlab原理和深度分析

SQL Injection (POST/Search)

Resolved (error in viewing data information in machine learning) attributeerror: target_ names

Golang - command line tool Cobra

Brief analysis of tensorboard visual processing cases

The solution of Chinese font garbled code in keil5
随机推荐
【被动收入如何挣个一百万】
ThreadPoolExecutor realizes multi-threaded concurrency and obtains the return value (elegant and concise way)
Spark practice 1: build spark operation environment in single node local mode
Stack application (balancer)
Flutter dynamic | fair 2.5.0 new version features
MapReduce implements matrix multiplication - implementation code
栈应用(平衡符)
使用Tensorflow进行完整的深度神经网络CNN训练完成图片识别案例2
物联网毕设 --(STM32f407连接云平台检测数据)
When updating mysql, the condition is a query
Kivy tutorial how to automatically load kV files
Unity EmbeddedBrowser浏览器插件事件通讯
双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
Libuv库 - 设计概述(中文版)
Libuv Library - Design Overview (Chinese version)
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
软件测试工作那么难找,只有外包offer,我该去么?
Go language unit test 4: go language uses gomonkey to test functions or methods
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Father and basketball