<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Cpp - 标签 - 研发日志 · R&amp;D Log</title><link>https://rd163.visword.com/tags/cpp/</link><description>Cpp - 标签 - 研发日志 · R&amp;D Log</description><generator>Hugo -- gohugo.io</generator><language>zh-CN</language><managingEditor>whutluohui@gmail.com (小智晖)</managingEditor><webMaster>whutluohui@gmail.com (小智晖)</webMaster><copyright>本作品采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可。</copyright><lastBuildDate>Thu, 05 Jun 2025 00:00:00 +0800</lastBuildDate><atom:link href="https://rd163.visword.com/tags/cpp/" rel="self" type="application/rss+xml"/><item><title>基于boost.asio的WebSocket类库</title><link>https://rd163.visword.com/posts/cpp-websocket-base-on-boost-asio/</link><pubDate>Thu, 05 Jun 2025 00:00:00 +0800</pubDate><author><name>小智晖</name></author><guid>https://rd163.visword.com/posts/cpp-websocket-base-on-boost-asio/</guid><description><![CDATA[<h2 id="zaphoydwebsocketpp" class="headerLink">
    <a href="#zaphoydwebsocketpp" class="header-mark"></a>zaphoyd/websocketpp</h2><p><a href="https://github.com/zaphoyd/websocketpp" target="_blank" rel="noopener noreferrer">WebSocket++ github </a></p>
<p>具有以下特点：</p>
<ul>
<li>Header Only的跨平台 WebSocket 库</li>
<li>网络 IO 基于 Boost::asio 实现</li>
<li>由于boost::asio 的 io_context 使用了线程存储,所以在 M:N 的协程模式(fiber) 下调用需格外小心。最好是采用 1:N 的协程。</li>
</ul>
<p>当服务作为客户端管理多个 Connection 时， 如果每个Connection 对象都使用一个 Client 对象， 由于 Client 在Connect（无论Url中使用IP还是域名） 时都会创建一个独立线程来进行域名解析，导致线程数过多，从而性能地下。</p>]]></description></item><item><title>trpc微服务寻址方案设计</title><link>https://rd163.visword.com/posts/trpc-service-addressing-scheme-design/</link><pubDate>Sun, 01 Jun 2025 00:00:00 +0800</pubDate><author><name>小智晖</name></author><guid>https://rd163.visword.com/posts/trpc-service-addressing-scheme-design/</guid><description><![CDATA[<h2 id="服务命名" class="headerLink">
    <a href="#%e6%9c%8d%e5%8a%a1%e5%91%bd%e5%90%8d" class="header-mark"></a>服务命名</h2><p>tRPC在服务命名上定义了以下3个纬度信息：</p>
<ul>
<li>app名（应用名），表示某个业务系统的名称，用于标识某个业务下不同服务模块的一个集合；</li>
<li>server名（模块名），表示具体服务模块的名称，一般也称为模块的进程名称；</li>
<li>service名，表示具体服务提供者的名称，一般使用proto文件定义的Service名称； 其中app.server 的组合在全局上要具备唯一性。</li>
</ul>
<p>服务命名这样定义的好处是：</p>]]></description></item><item><title>C/C++面试基础知识</title><link>https://rd163.visword.com/posts/cpp-interview/</link><pubDate>Thu, 08 May 2025 00:00:00 +0800</pubDate><author><name>小智晖</name></author><guid>https://rd163.visword.com/posts/cpp-interview/</guid><description><![CDATA[<h2 id="cc-basics" class="headerLink">
    <a href="#cc-basics" class="header-mark"></a>C/C++ Basics</h2><h3 id="如何定义一个只能在堆上栈上生成对象的类" class="headerLink">
    <a href="#%e5%a6%82%e4%bd%95%e5%ae%9a%e4%b9%89%e4%b8%80%e4%b8%aa%e5%8f%aa%e8%83%bd%e5%9c%a8%e5%a0%86%e4%b8%8a%e6%a0%88%e4%b8%8a%e7%94%9f%e6%88%90%e5%af%b9%e8%b1%a1%e7%9a%84%e7%b1%bb" class="header-mark"></a>如何定义一个只能在堆上（栈上）生成对象的类？</h3><blockquote>
  <p><a href="https://www.nowcoder.com/questionTerminal/0a584aa13f804f3ea72b442a065a7618" target="_blank" rel="noopener noreferrer">如何定义一个只能在堆上（栈上）生成对象的类?</a></p>

</blockquote><h4 id="只能在堆上" class="headerLink">
    <a href="#%e5%8f%aa%e8%83%bd%e5%9c%a8%e5%a0%86%e4%b8%8a" class="header-mark"></a>只能在堆上</h4><p>方法：将析构函数设置为私有</p>
<p>原因：C++ 是静态绑定语言，编译器管理栈上对象的生命周期，编译器在为类对象分配栈空间时，会先检查类的析构函数的访问性。若析构函数不可访问，则不能在栈上创建对象。</p>]]></description></item><item><title>Boost.Asio 简介</title><link>https://rd163.visword.com/posts/cpp-boost-asio-intro/</link><pubDate>Tue, 08 Apr 2025 00:00:00 +0800</pubDate><author><name>小智晖</name></author><guid>https://rd163.visword.com/posts/cpp-boost-asio-intro/</guid><description><![CDATA[<h2 id="概述" class="headerLink">
    <a href="#%e6%a6%82%e8%bf%b0" class="header-mark"></a>概述</h2><p>Boost.Asio是一个跨平台的、主要用于网络和其他一些底层输入/输出编程的C++库。</p>
<p>Asio，即「异步 IO」（Asynchronous Input/Output），本是一个 <a href="http://think-async.com/Asio" target="_blank" rel="noopener noreferrer">独立的 C++ 网络程序库</a>，似乎并不为人所知，后来因为被 Boost 相中，才声名鹊起。</p>]]></description></item><item><title>c++ Promise/Future模型</title><link>https://rd163.visword.com/posts/cpp-promise-future-intro/</link><pubDate>Sun, 06 Apr 2025 00:00:00 +0800</pubDate><author><name>小智晖</name></author><guid>https://rd163.visword.com/posts/cpp-promise-future-intro/</guid><description>&lt;p>Promise/Future是一种经典的异步抽象，由于其“标准化”的概念，提供了很多可能性。这就如同工业史的集装箱、软件界的docker，由于其“标准化”，不同组件可以简单地自由组合，从而提升了整体效率。&lt;/p></description></item><item><title>c++20协程简介</title><link>https://rd163.visword.com/posts/cpp20-corouting-intro/</link><pubDate>Sun, 06 Apr 2025 00:00:00 +0800</pubDate><author><name>小智晖</name></author><guid>https://rd163.visword.com/posts/cpp20-corouting-intro/</guid><description><![CDATA[<h2 id="c20协程简介" class="headerLink">
    <a href="#c20%e5%8d%8f%e7%a8%8b%e7%ae%80%e4%bb%8b" class="header-mark"></a>c++20协程简介</h2><p>参考：</p>
<ul>
<li><a href="https://github.com/0voice/cpp_backend_awsome_blog/blob/main/%E3%80%90NO.241%E3%80%91%E5%8D%8F%E7%A8%8B%E5%8F%8Ac%2B%2B%2020%E5%8E%9F%E7%94%9F%E5%8D%8F%E7%A8%8B%E7%A0%94%E7%A9%B6%E6%8A%A5%E5%91%8A.md" target="_blank" rel="noopener noreferrer">协程及c++ 20原生协程研究报告</a></li>
<li><a href="https://0cch.com/uploads/2022/02/k&#43;2021.pdf" target="_blank" rel="noopener noreferrer">2021K+ 全球软件研发行业创新峰会 深入解析C++20协程</a></li>
</ul>
<p>C++20协程通过Promise和Awaitable接口的15个以上的函数来提供给程序员定制协程的流程和功能，实现最简单的协程需要用到其中的8个（5个Promise的函数和3个Awaitable的函数），
先来看Awaitable的3个函数。</p>]]></description></item><item><title>trpc-cpp流式服务</title><link>https://rd163.visword.com/posts/trpc-cpp-stream-service/</link><pubDate>Tue, 01 Apr 2025 00:00:00 +0800</pubDate><author><name>小智晖</name></author><guid>https://rd163.visword.com/posts/trpc-cpp-stream-service/</guid><description><![CDATA[<h2 id="流式应用场景" class="headerLink">
    <a href="#%e6%b5%81%e5%bc%8f%e5%ba%94%e7%94%a8%e5%9c%ba%e6%99%af" class="header-mark"></a>流式应用场景</h2><ul>
<li>大规模数据包。 比如，有一个大文件需要传输。 使用流式 RPC 时，客户端分片读出文件内容后直接写入到流中，服务端可以按客户端写入顺序读取到文件分片内容，然后执行业务逻辑。 如果使用单次 RPC，需要多次调用RPC方法，会遇到分包、组包、乱序、业务逻辑上下文切换等问题。</li>
<li>实时场景。 比如，股票行情走势，资讯 Feeds 流。 服务端接收到消息后，需要往多个客户端进行实时消息推送，流式 RPC 可以在一次 RPC 调用过程中，推送完整的消息列表。</li>
<li>Istio、Envoy、Nacos 等项目，内部都是用 gRPC 作为通信协议来实现控制平面</li>
</ul>
<h2 id="三种流式-rpc-方法" class="headerLink">
    <a href="#%e4%b8%89%e7%a7%8d%e6%b5%81%e5%bc%8f-rpc-%e6%96%b9%e6%b3%95" class="header-mark"></a>三种流式 RPC 方法</h2><p>tRPC 协议的流式 RPC 分为三种类型：</p>]]></description></item><item><title>C++协程介绍</title><link>https://rd163.visword.com/posts/fiber-intro-for-cpp/</link><pubDate>Mon, 31 Mar 2025 00:00:00 +0800</pubDate><author><name>小智晖</name></author><guid>https://rd163.visword.com/posts/fiber-intro-for-cpp/</guid><description><![CDATA[<h2 id="协程corouting与纤程fiber区别" class="headerLink">
    <a href="#%e5%8d%8f%e7%a8%8bcorouting%e4%b8%8e%e7%ba%a4%e7%a8%8bfiber%e5%8c%ba%e5%88%ab" class="header-mark"></a>协程(corouting)与纤程(fiber)区别</h2><h3 id="协程coroutine" class="headerLink">
    <a href="#%e5%8d%8f%e7%a8%8bcoroutine" class="header-mark"></a>协程（Coroutine）​</h3><p>N:1协程</p>
<p>协程是语言级别的特性（C++20原生支持），由编译器生成状态机逻辑，通过co_await、co_yield等关键字实现隐式挂起和恢复，无需直接操作底层上下文。</p>]]></description></item><item><title>C++内存泄露检测工具</title><link>https://rd163.visword.com/posts/memleak-check-tools-for-cpp/</link><pubDate>Sat, 22 Mar 2025 00:00:00 +0800</pubDate><author><name>小智晖</name></author><guid>https://rd163.visword.com/posts/memleak-check-tools-for-cpp/</guid><description><![CDATA[<p>在服务器后台开发中，排查和定位C++内存泄漏的常用工具和方法可分为以下几类，结合其特点和使用场景进行选择：</p>
<hr>
<h2 id="工具分类" class="headerLink">
    <a href="#%e5%b7%a5%e5%85%b7%e5%88%86%e7%b1%bb" class="header-mark"></a>工具分类</h2><h3 id="1-动态检测工具" class="headerLink">
    <a href="#1-%e5%8a%a8%e6%80%81%e6%a3%80%e6%b5%8b%e5%b7%a5%e5%85%b7" class="header-mark"></a><strong>1. 动态检测工具</strong></h3><h4 id="valgrind-memcheck" class="headerLink">
    <a href="#valgrind-memcheck" class="header-mark"></a><strong>Valgrind Memcheck</strong></h4><ul>
<li>
<p><strong>特点</strong>：</p>
<ul>
<li>• Linux下经典工具，检测内存泄漏、越界访问、未初始化内存等问题。</li>
<li>• 无需重新编译代码（但建议编译时保留调试符号 <code>-g</code>）。</li>
<li>• 运行速度较慢，适合测试环境。</li>
</ul>
</li>
<li>
<p><strong>使用方式</strong>：</p>]]></description></item><item><title>C/C++ 实现的服务器和服务器相关的库</title><link>https://rd163.visword.com/posts/cpp-servers/</link><pubDate>Sun, 12 Jan 2025 00:00:00 +0800</pubDate><author><name>小智晖</name></author><guid>https://rd163.visword.com/posts/cpp-servers/</guid><description><![CDATA[<h1 id="cc-实现的服务器和服务器相关的库" class="headerLink">
    <a href="#cc-%e5%ae%9e%e7%8e%b0%e7%9a%84%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%92%8c%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9b%b8%e5%85%b3%e7%9a%84%e5%ba%93" class="header-mark"></a>C/C++ 实现的服务器和服务器相关的库</h1><h2 id="http-server" class="headerLink">
    <a href="#http-server" class="header-mark"></a>Http Server</h2><h3 id="nginx" class="headerLink">
    <a href="#nginx" class="header-mark"></a>NGINX</h3><h3 id="haproxy" class="headerLink">
    <a href="#haproxy" class="header-mark"></a>HAProxy</h3><h3 id="envoy" class="headerLink">
    <a href="#envoy" class="header-mark"></a>Envoy</h3><h3 id="apache-http-server" class="headerLink">
    <a href="#apache-http-server" class="header-mark"></a>Apache HTTP Server</h3><h3 id="apache-traffic-server" class="headerLink">
    <a href="#apache-traffic-server" class="header-mark"></a>Apache Traffic Server</h3><ul>
<li><a href="https://github.com/apache/trafficserver" target="_blank" rel="noopener noreferrer">Apache Traffic Server</a></li>
</ul>
<p>Apache Traffic Server™ 是一种高性能 Web 代理缓存，它通过在网络边缘缓存经常访问的信息来提高网络效率和性能。这使内容在物理上更接近最终用户，同时实现更快的交付并减少带宽使用。Traffic Server 旨在通过最大化现有和可用带宽来改善企业、互联网服务提供商 (ISP)、骨干提供商和大型 Intranet 的内容交付。</p>]]></description></item></channel></rss>