Boost Asio总结(9)数据缓冲区class mutable_buffer和const_buffer

2024-03-28 08:18

本文主要是介绍Boost Asio总结(9)数据缓冲区class mutable_buffer和const_buffer,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

保存了一个void*的内存地址和数据长度。

/// Holds a buffer that can be modified.
class mutable_buffer
{
public:/// Construct an empty buffer.mutable_buffer() BOOST_ASIO_NOEXCEPT: data_(0),size_(0){}/// Construct a buffer to represent a given memory range.mutable_buffer(void* data, std::size_t size) BOOST_ASIO_NOEXCEPT: data_(data),size_(size){}#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)mutable_buffer(void* data, std::size_t size,boost::asio::detail::function<void()> debug_check): data_(data),size_(size),debug_check_(debug_check){}const boost::asio::detail::function<void()>& get_debug_check() const{return debug_check_;}
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING/// Get a pointer to the beginning of the memory range.void* data() const BOOST_ASIO_NOEXCEPT{
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)if (size_ && debug_check_)debug_check_();
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGINGreturn data_;}/// Get the size of the memory range.std::size_t size() const BOOST_ASIO_NOEXCEPT{return size_;}/// Move the start of the buffer by the specified number of bytes.mutable_buffer& operator+=(std::size_t n) BOOST_ASIO_NOEXCEPT{std::size_t offset = n < size_ ? n : size_;data_ = static_cast<char*>(data_) + offset;size_ -= offset;return *this;}private:void* data_;std::size_t size_;#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)boost::asio::detail::function<void()> debug_check_;
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
};/// Holds a buffer that cannot be modified.class const_buffer
{
public:/// Construct an empty buffer.const_buffer() BOOST_ASIO_NOEXCEPT: data_(0),size_(0){}/// Construct a buffer to represent a given memory range.const_buffer(const void* data, std::size_t size) BOOST_ASIO_NOEXCEPT: data_(data),size_(size){}/// Construct a non-modifiable buffer from a modifiable one.const_buffer(const mutable_buffer& b) BOOST_ASIO_NOEXCEPT: data_(b.data()),size_(b.size())
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING), debug_check_(b.get_debug_check())
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING{}#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)const_buffer(const void* data, std::size_t size,boost::asio::detail::function<void()> debug_check): data_(data),size_(size),debug_check_(debug_check){}const boost::asio::detail::function<void()>& get_debug_check() const{return debug_check_;}
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING/// Get a pointer to the beginning of the memory range.const void* data() const BOOST_ASIO_NOEXCEPT{
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)if (size_ && debug_check_)debug_check_();
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGINGreturn data_;}/// Get the size of the memory range.std::size_t size() const BOOST_ASIO_NOEXCEPT{return size_;}/// Move the start of the buffer by the specified number of bytes.const_buffer& operator+=(std::size_t n) BOOST_ASIO_NOEXCEPT{std::size_t offset = n < size_ ? n : size_;data_ = static_cast<const char*>(data_) + offset;size_ -= offset;return *this;}private:const void* data_;std::size_t size_;#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)boost::asio::detail::function<void()> debug_check_;
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
};class mutable_buffers_1: public mutable_buffer
{
public:/// The type for each element in the list of buffers.typedef mutable_buffer value_type;/// A random-access iterator type that may be used to read elements.typedef const mutable_buffer* const_iterator;/// Get a random-access iterator to the first element.const_iterator begin() const BOOST_ASIO_NOEXCEPT{return this;}/// Get a random-access iterator for one past the last element.const_iterator end() const BOOST_ASIO_NOEXCEPT{return begin() + 1;}
};class const_buffers_1: public const_buffer
{
public:/// The type for each element in the list of buffers.typedef const_buffer value_type;/// A random-access iterator type that may be used to read elements.typedef const const_buffer* const_iterator;/// Construct to represent a given memory range.const_buffers_1(const void* data, std::size_t size) BOOST_ASIO_NOEXCEPT: const_buffer(data, size){}#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)const_buffers_1(const void* data, std::size_t size,boost::asio::detail::function<void()> debug_check): const_buffer(data, size, debug_check){}
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING/// Construct to represent a single non-modifiable buffer.explicit const_buffers_1(const const_buffer& b) BOOST_ASIO_NOEXCEPT: const_buffer(b){}/// Get a random-access iterator to the first element.const_iterator begin() const BOOST_ASIO_NOEXCEPT{return this;}/// Get a random-access iterator for one past the last element.const_iterator end() const BOOST_ASIO_NOEXCEPT{return begin() + 1;}
};

这篇关于Boost Asio总结(9)数据缓冲区class mutable_buffer和const_buffer的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/855017

相关文章

JavaSE正则表达式用法总结大全

《JavaSE正则表达式用法总结大全》正则表达式就是由一些特定的字符组成,代表的是一个规则,:本文主要介绍JavaSE正则表达式用法的相关资料,文中通过代码介绍的非常详细,需要的朋友可以参考下... 目录常用的正则表达式匹配符正则表China编程达式常用的类Pattern类Matcher类PatternSynta

MyBatisPlus如何优化千万级数据的CRUD

《MyBatisPlus如何优化千万级数据的CRUD》最近负责的一个项目,数据库表量级破千万,每次执行CRUD都像走钢丝,稍有不慎就引起数据库报警,本文就结合这个项目的实战经验,聊聊MyBatisPl... 目录背景一、MyBATis Plus 简介二、千万级数据的挑战三、优化 CRUD 的关键策略1. 查

python实现对数据公钥加密与私钥解密

《python实现对数据公钥加密与私钥解密》这篇文章主要为大家详细介绍了如何使用python实现对数据公钥加密与私钥解密,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录公钥私钥的生成使用公钥加密使用私钥解密公钥私钥的生成这一部分,使用python生成公钥与私钥,然后保存在两个文

mysql中的数据目录用法及说明

《mysql中的数据目录用法及说明》:本文主要介绍mysql中的数据目录用法及说明,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、背景2、版本3、数据目录4、总结1、背景安装mysql之后,在安装目录下会有一个data目录,我们创建的数据库、创建的表、插入的

解析C++11 static_assert及与Boost库的关联从入门到精通

《解析C++11static_assert及与Boost库的关联从入门到精通》static_assert是C++中强大的编译时验证工具,它能够在编译阶段拦截不符合预期的类型或值,增强代码的健壮性,通... 目录一、背景知识:传统断言方法的局限性1.1 assert宏1.2 #error指令1.3 第三方解决

Navicat数据表的数据添加,删除及使用sql完成数据的添加过程

《Navicat数据表的数据添加,删除及使用sql完成数据的添加过程》:本文主要介绍Navicat数据表的数据添加,删除及使用sql完成数据的添加过程,具有很好的参考价值,希望对大家有所帮助,如有... 目录Navicat数据表数据添加,删除及使用sql完成数据添加选中操作的表则出现如下界面,查看左下角从左

SpringBoot中4种数据水平分片策略

《SpringBoot中4种数据水平分片策略》数据水平分片作为一种水平扩展策略,通过将数据分散到多个物理节点上,有效解决了存储容量和性能瓶颈问题,下面小编就来和大家分享4种数据分片策略吧... 目录一、前言二、哈希分片2.1 原理2.2 SpringBoot实现2.3 优缺点分析2.4 适用场景三、范围分片

Redis分片集群、数据读写规则问题小结

《Redis分片集群、数据读写规则问题小结》本文介绍了Redis分片集群的原理,通过数据分片和哈希槽机制解决单机内存限制与写瓶颈问题,实现分布式存储和高并发处理,但存在通信开销大、维护复杂及对事务支持... 目录一、分片集群解android决的问题二、分片集群图解 分片集群特征如何解决的上述问题?(与哨兵模

浅析如何保证MySQL与Redis数据一致性

《浅析如何保证MySQL与Redis数据一致性》在互联网应用中,MySQL作为持久化存储引擎,Redis作为高性能缓存层,两者的组合能有效提升系统性能,下面我们来看看如何保证两者的数据一致性吧... 目录一、数据不一致性的根源1.1 典型不一致场景1.2 关键矛盾点二、一致性保障策略2.1 基础策略:更新数

Oracle 数据库数据操作如何精通 INSERT, UPDATE, DELETE

《Oracle数据库数据操作如何精通INSERT,UPDATE,DELETE》在Oracle数据库中,对表内数据进行增加、修改和删除操作是通过数据操作语言来完成的,下面给大家介绍Oracle数... 目录思维导图一、插入数据 (INSERT)1.1 插入单行数据,指定所有列的值语法:1.2 插入单行数据,指