1. Buffer模块 Buffer模块:缓冲区模块 提供的功能:存储数据,取出数据 实现思想: 实现缓冲区得有一块内存空间,采用vector,vector底层其实使用的就是一个线性的内存空间。不用string的原因是因为,网络传输数据什么都有而string在读取遇 ‘\0’ 就停止了。 要素: 默认的空间大小 当前的读取数据位置 当前的写入数据位置 操作: a. 写入数据: 当前写入位置指向哪里,就从哪里开始写入。 如果后续剩余空闲空间不够了,考虑整体缓冲区空闲空间是否足够(因为读位置也会向后偏移,前边有可能会有空闲空间)。 足够:将数据移动到起始位置即可 不够:扩容,从当前写位置开始扩容足够大小 数据一旦写入成功,当前写位置,就要向后偏移 b.
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Get in touch with moveWrite
Contact moveWrite, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack