<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Winsome I Write</title>
    <link>https://yeahohooh.github.io/</link>
    <description>Recent content on Winsome I Write</description>
    <generator>Hugo</generator>
    <language>zh-CN</language>
    <copyright>This work is licensed under the MIT License.</copyright>
    <lastBuildDate>Sun, 24 May 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://yeahohooh.github.io/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Privacy Policy</title>
      <link>https://yeahohooh.github.io/privacy_kiro-cam/</link>
      <pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate>
      <guid>https://yeahohooh.github.io/privacy_kiro-cam/</guid>
      <description>&lt;p&gt;KIRO Cam respects your privacy.&lt;/p&gt;&#xA;&lt;p&gt;This Privacy Policy explains how KIRO Cam handles information when you use the app.&lt;/p&gt;&#xA;&lt;h2 id=&#34;no-account-required&#34;&gt;No Account Required&lt;a href=&#34;#no-account-required&#34; class=&#34;anchor&#34; aria-hidden=&#34;true&#34;&gt;&lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34; stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34;&#xA;      stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;&#xA;      &lt;path d=&#34;M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3&#34;&gt;&lt;/path&gt;&#xA;      &lt;line x1=&#34;8&#34; y1=&#34;12&#34; x2=&#34;16&#34; y2=&#34;12&#34;&gt;&lt;/line&gt;&#xA;   &lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;KIRO Cam does not require registration or login.&lt;/p&gt;&#xA;&lt;p&gt;You can use the app without creating an account.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Technical Support</title>
      <link>https://yeahohooh.github.io/support_kiro-cam/</link>
      <pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate>
      <guid>https://yeahohooh.github.io/support_kiro-cam/</guid>
      <description>&lt;p&gt;Thank you for using KIRO Cam.&lt;/p&gt;&#xA;&lt;p&gt;If you have any questions, suggestions, bug reports, or feedback, feel free to contact us.&lt;/p&gt;&#xA;&lt;h2 id=&#34;contact&#34;&gt;Contact&lt;a href=&#34;#contact&#34; class=&#34;anchor&#34; aria-hidden=&#34;true&#34;&gt;&lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34; stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34;&#xA;      stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;&#xA;      &lt;path d=&#34;M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3&#34;&gt;&lt;/path&gt;&#xA;      &lt;line x1=&#34;8&#34; y1=&#34;12&#34; x2=&#34;16&#34; y2=&#34;12&#34;&gt;&lt;/line&gt;&#xA;   &lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;Email: &lt;a href=&#34;mailto:tc346492283@gmail.com&#34;&gt;tc346492283@gmail.com&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;We will do our best to respond as soon as possible.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Privacy Policy</title>
      <link>https://yeahohooh.github.io/privacy_deviceanalyzer/</link>
      <pubDate>Tue, 05 May 2026 00:00:00 +0000</pubDate>
      <guid>https://yeahohooh.github.io/privacy_deviceanalyzer/</guid>
      <description>&lt;p&gt;Welcome to &amp;ldquo;Device Analyzer&amp;rdquo; App (hereinafter referred to as &amp;ldquo;the App&amp;rdquo;). This Privacy Policy explains how the App handles user information and the rights of users while using the App.&lt;/p&gt;&#xA;&lt;h2 id=&#34;1-information-collection&#34;&gt;1. Information Collection&lt;a href=&#34;#1-information-collection&#34; class=&#34;anchor&#34; aria-hidden=&#34;true&#34;&gt;&lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34; stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34;&#xA;      stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;&#xA;      &lt;path d=&#34;M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3&#34;&gt;&lt;/path&gt;&#xA;      &lt;line x1=&#34;8&#34; y1=&#34;12&#34; x2=&#34;16&#34; y2=&#34;12&#34;&gt;&lt;/line&gt;&#xA;   &lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;The App is an offline app, does not require login, and does not connect to the Internet. Except for voluntary actions by users, the App &lt;strong&gt;does not collect, store, or transmit any personal information&lt;/strong&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Device Analyzer Support</title>
      <link>https://yeahohooh.github.io/support_deviceanalyzer/</link>
      <pubDate>Fri, 01 May 2026 00:00:00 +0000</pubDate>
      <guid>https://yeahohooh.github.io/support_deviceanalyzer/</guid>
      <description>&lt;p&gt;Thank you for using Device Analyzer.&lt;/p&gt;&#xA;&lt;p&gt;If you encounter any issues or have suggestions, please contact us:&lt;/p&gt;&#xA;&lt;p&gt;Email: &lt;a href=&#34;mailto:tc346492283@gmail.com&#34;&gt;tc346492283@gmail.com&lt;/a&gt;&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;感谢使用 Device Analyzer。&lt;/p&gt;&#xA;&lt;p&gt;如果你在使用过程中遇到问题或有任何建议，欢迎联系我们：&lt;/p&gt;&#xA;&lt;p&gt;邮箱：tc346492283@gmail.com&lt;/p&gt;</description>
    </item>
    <item>
      <title>CheerGlow Support</title>
      <link>https://yeahohooh.github.io/support/</link>
      <pubDate>Sun, 29 Mar 2026 00:00:00 +0000</pubDate>
      <guid>https://yeahohooh.github.io/support/</guid>
      <description>&lt;p&gt;Thank you for using CheerGlow.&lt;/p&gt;&#xA;&lt;p&gt;If you encounter any issues or have suggestions, please contact us:&lt;/p&gt;&#xA;&lt;p&gt;Email: &lt;a href=&#34;mailto:tc346492283@gmail.com&#34;&gt;tc346492283@gmail.com&lt;/a&gt;&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;感谢使用 我的应援色。&lt;/p&gt;&#xA;&lt;p&gt;如果你在使用过程中遇到问题或有任何建议，欢迎联系我们：&lt;/p&gt;&#xA;&lt;p&gt;邮箱：tc346492283@gmail.com&lt;/p&gt;</description>
    </item>
    <item>
      <title>Privacy Policy</title>
      <link>https://yeahohooh.github.io/privacy/</link>
      <pubDate>Sat, 28 Mar 2026 00:00:00 +0000</pubDate>
      <guid>https://yeahohooh.github.io/privacy/</guid>
      <description>&lt;p&gt;Welcome to &amp;ldquo;CheerGlow&amp;rdquo; App (hereinafter referred to as &amp;ldquo;the App&amp;rdquo;). This Privacy Policy explains how the App handles user information and the rights of users while using the App.&lt;/p&gt;&#xA;&lt;h2 id=&#34;1-information-collection&#34;&gt;1. Information Collection&lt;a href=&#34;#1-information-collection&#34; class=&#34;anchor&#34; aria-hidden=&#34;true&#34;&gt;&lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34; stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34;&#xA;      stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;&#xA;      &lt;path d=&#34;M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3&#34;&gt;&lt;/path&gt;&#xA;      &lt;line x1=&#34;8&#34; y1=&#34;12&#34; x2=&#34;16&#34; y2=&#34;12&#34;&gt;&lt;/line&gt;&#xA;   &lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;The App is an offline app, does not require login, and does not connect to the Internet. Except for voluntary actions by users, the App &lt;strong&gt;does not collect, store, or transmit any personal information&lt;/strong&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>About</title>
      <link>https://yeahohooh.github.io/about/</link>
      <pubDate>Wed, 10 Sep 2025 12:00:00 +0800</pubDate>
      <guid>https://yeahohooh.github.io/about/</guid>
      <description>&lt;p&gt;嗨 👋&lt;/p&gt;&#xA;&lt;p&gt;我是一个 &lt;strong&gt;iOS 搬砖工 + Go 搬服务器的苦力&lt;/strong&gt;。&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;在苹果生态里，我和 &lt;strong&gt;Xcode&lt;/strong&gt; 打了无数场架，大部分时间是输的。&lt;/li&gt;&#xA;&lt;li&gt;在 Go 世界里，我和 &lt;strong&gt;Goroutine&lt;/strong&gt; 是好朋友，但有时候它们开得太多，我自己都数不过来。&lt;/li&gt;&#xA;&lt;li&gt;部署的时候，我总觉得 &lt;strong&gt;Bug&lt;/strong&gt; 比代码跑得还快。&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;为什么写博客&#34;&gt;为什么写博客？&lt;a href=&#34;#%e4%b8%ba%e4%bb%80%e4%b9%88%e5%86%99%e5%8d%9a%e5%ae%a2&#34; class=&#34;anchor&#34; aria-hidden=&#34;true&#34;&gt;&lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34; stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34;&#xA;      stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;&#xA;      &lt;path d=&#34;M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3&#34;&gt;&lt;/path&gt;&#xA;      &lt;line x1=&#34;8&#34; y1=&#34;12&#34; x2=&#34;16&#34; y2=&#34;12&#34;&gt;&lt;/line&gt;&#xA;   &lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;&#xA;&lt;p&gt;其实是因为记性不好，写下来方便以后查。&lt;br&gt;&#xA;顺便装作自己很懂的样子，结果有时候看回自己写的东西也会“啊？这是我写的？”🤯&lt;/p&gt;&#xA;&lt;h3 id=&#34;技能树&#34;&gt;技能树&lt;a href=&#34;#%e6%8a%80%e8%83%bd%e6%a0%91&#34; class=&#34;anchor&#34; aria-hidden=&#34;true&#34;&gt;&lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34; stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34;&#xA;      stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;&#xA;      &lt;path d=&#34;M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3&#34;&gt;&lt;/path&gt;&#xA;      &lt;line x1=&#34;8&#34; y1=&#34;12&#34; x2=&#34;16&#34; y2=&#34;12&#34;&gt;&lt;/line&gt;&#xA;   &lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Swift/Object-C：能写出能跑的 iOS App。&lt;/li&gt;&#xA;&lt;li&gt;Go：能写出大部分时候能跑的服务。&lt;/li&gt;&#xA;&lt;li&gt;Docker/Nginx：配置成功过几次，至今都觉得是奇迹。&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;人生苦短，Bug 无数。&lt;br&gt;&#xA;我只负责记录，解决交给未来的自己。&lt;/p&gt;</description>
    </item>
    <item>
      <title>Docker 搭建 Redis Cluster 集群</title>
      <link>https://yeahohooh.github.io/posts/docker%E6%90%AD%E5%BB%BArediscluster%E9%9B%86%E7%BE%A4/</link>
      <pubDate>Fri, 01 Nov 2024 18:40:15 +0800</pubDate>
      <guid>https://yeahohooh.github.io/posts/docker%E6%90%AD%E5%BB%BArediscluster%E9%9B%86%E7%BE%A4/</guid>
      <description>&lt;p&gt;本文仅介绍 Redis Cluster 模式，也是官方推荐的模式。&lt;/p&gt;&#xA;&lt;p&gt;为了保证高可用性，Redis 要求 Cluster 模式至少需要3个主节点，而每个主节点至少要配备一个从属节点，因此我们至少需要6个节点才能搭建起来一个Redis 的 Cluster 集群。&lt;/p&gt;&#xA;&lt;p&gt;例子中都写到了同一个服务器，实际中可以拆开放到多个服务器，只需要把相应的内容分开就好。&lt;/p&gt;&#xA;&lt;h4 id=&#34;前期准备&#34;&gt;前期准备&lt;a href=&#34;#%e5%89%8d%e6%9c%9f%e5%87%86%e5%a4%87&#34; class=&#34;anchor&#34; aria-hidden=&#34;true&#34;&gt;&lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34; stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34;&#xA;      stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;&#xA;      &lt;path d=&#34;M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3&#34;&gt;&lt;/path&gt;&#xA;      &lt;line x1=&#34;8&#34; y1=&#34;12&#34; x2=&#34;16&#34; y2=&#34;12&#34;&gt;&lt;/line&gt;&#xA;   &lt;/svg&gt;&lt;/a&gt;&lt;/h4&gt;&#xA;&lt;p&gt;&lt;strong&gt;拉取 redis 镜像&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;docker pull redis&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;创建 Docker 容器网络&lt;/strong&gt;&#xA;主要是用于redis-cluster能于外界进行网络通信，一般常用桥接模式。&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;docker network create redis-cluster-net&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;编写配置文件&lt;/strong&gt;&#xA;创建 Redis 宿主机配置文件&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# 创建文件夹，7000 是将要设置的端口号，所以先用这个命名&#xA;sudo mkdir -p /data/redis7000/conf&#xA;# 创建配置文件&#xA;cd /data/redis7000/conf&#xA;sudo nano redis-cluster.conf&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;配置内容如下：&lt;/p&gt;</description>
    </item>
    <item>
      <title>Mysql 主从复制 读写分离 nginx 负载均衡</title>
      <link>https://yeahohooh.github.io/posts/mysql%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BBnginx%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1/</link>
      <pubDate>Fri, 25 Oct 2024 18:36:33 +0800</pubDate>
      <guid>https://yeahohooh.github.io/posts/mysql%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BBnginx%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1/</guid>
      <description>&lt;p&gt;记录一篇流水账，关于这些配置。&lt;/p&gt;&#xA;&lt;p&gt;场景概述：&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;服务器 A：将作为主服务器，Nginx 运行在 8080 端口。&lt;/li&gt;&#xA;&lt;li&gt;服务器 B：将作为从服务器，Nginx 运行在 80 端口。&lt;/li&gt;&#xA;&lt;li&gt;负载均衡目标：Nginx 实现两台服务器的流量均衡，将请求分发到两台服务器上。但写请求永远发送到主节点，读请求可以发往主或从节点。&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;mysql-主从复制配置&#34;&gt;MySQL 主从复制配置&lt;a href=&#34;#mysql-%e4%b8%bb%e4%bb%8e%e5%a4%8d%e5%88%b6%e9%85%8d%e7%bd%ae&#34; class=&#34;anchor&#34; aria-hidden=&#34;true&#34;&gt;&lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; viewBox=&#34;0 0 24 24&#34; fill=&#34;none&#34; stroke=&#34;currentColor&#34; stroke-width=&#34;2&#34;&#xA;      stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;&#xA;      &lt;path d=&#34;M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3&#34;&gt;&lt;/path&gt;&#xA;      &lt;line x1=&#34;8&#34; y1=&#34;12&#34; x2=&#34;16&#34; y2=&#34;12&#34;&gt;&lt;/line&gt;&#xA;   &lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;&#xA;&lt;p&gt;1.1 主服务器 A（Master）的 MySQL 配置：&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;修改 MySQL 配置文件 /etc/mysql/mysql.conf.d/mysqld.cnf：&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;cd 进入该文件夹，然后 &lt;code&gt;sudo nano mysqld.cnf&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;下面的配置如果原文件没有就添加进去&lt;/li&gt;&#xA;&lt;li&gt;ctl + o 保存，ctl + x 退出&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[mysqld]&#xA;server-id = 1                   # 唯一的服务器ID，主从服务器ID不能相同&#xA;log_bin = /var/log/mysql/mysql-bin.log  # 启用二进制日志&#xA;binlog_format = row             # 使用行格式日志&#xA;bind-address    = 0.0.0.0       # 允许所有网络接口&#xA;port            = 3306          # 端口 默认3306，可以改为别的&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&#34;2&#34;&gt;&#xA;&lt;li&gt;重启 MySQL 服务：&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;sudo systemctl restart mysql&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&#34;3&#34;&gt;&#xA;&lt;li&gt;创建复制用户：&#xA;&lt;code&gt;mysql -u root -p&lt;/code&gt; 进入mysql&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CREATE USER &amp;#39;replicator&amp;#39;@&amp;#39;%&amp;#39; IDENTIFIED BY &amp;#39;password&amp;#39;;  -- 创建复制用户&#xA;GRANT REPLICATION SLAVE ON *.* TO &amp;#39;replicator&amp;#39;@&amp;#39;%&amp;#39;;     -- 赋予复制权限&#xA;FLUSH PRIVILEGES;                                    -- 刷新权限&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&#34;4&#34;&gt;&#xA;&lt;li&gt;获取主服务器的二进制日志信息：&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SHOW MASTER STATUS;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;记录下 File 和 Position，在从服务器配置时需要使用。&lt;/strong&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Go 语言中局部变量的堆栈</title>
      <link>https://yeahohooh.github.io/posts/go%E8%AF%AD%E8%A8%80%E4%B8%AD%E5%B1%80%E9%83%A8%E5%8F%98%E9%87%8F%E7%9A%84%E5%A0%86%E6%A0%88/</link>
      <pubDate>Wed, 16 Oct 2024 18:27:39 +0800</pubDate>
      <guid>https://yeahohooh.github.io/posts/go%E8%AF%AD%E8%A8%80%E4%B8%AD%E5%B1%80%E9%83%A8%E5%8F%98%E9%87%8F%E7%9A%84%E5%A0%86%E6%A0%88/</guid>
      <description>&lt;p&gt;在 Go 语言中，局部变量&lt;strong&gt;通常分配在栈上&lt;/strong&gt;，栈内存用于&lt;strong&gt;存储局部变量和函数调用信息&lt;/strong&gt;。当局部变量的生命周期超出了函数的作用范围，或当局部变量被传递给其他函数且可能被持久化时，Go 的编译器会将其&lt;strong&gt;转移到堆上&lt;/strong&gt;，这种机制称为“&lt;strong&gt;逃逸分析&lt;/strong&gt;”。&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;1）&lt;strong&gt;逃逸分析&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;在 Go 语言中，逃逸分析是一种&lt;strong&gt;编译时优化技术&lt;/strong&gt;，用于确定变量的生命周期及其存储位置（栈或堆）。通过逃逸分析，Go 编译器可以决定哪些变量应该分配在栈上，哪些应该分配在堆上。同时，编译器能优化内存使用，提高程序的性能。&lt;/p&gt;&#xA;&lt;p&gt;2）&lt;strong&gt;栈分配&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;&lt;strong&gt;局部变量&lt;/strong&gt;： 通常情况下，局部变量在函数调用期间分配在栈上。栈分配的变量在函数返回时会自动释放，因此其生命周期仅限于函数的执行期间。&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;&lt;strong&gt;栈的优势&lt;/strong&gt;： 栈分配通常比堆分配更高效，因为栈的内存管理相对简单，变量的分配和释放操作速度更快。&#xA;3）&lt;strong&gt;堆分配&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;&lt;strong&gt;逃逸变量&lt;/strong&gt;： 如果局部变量的生命周期超出了其所在的函数作用域（例如：它被返回或被引用到其他地方），则该变量会“&lt;strong&gt;逃逸&lt;/strong&gt;”到堆上。堆内存需要显式的垃圾回收来管理，这样变量在函数返回后仍然可以被访问。&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;&lt;strong&gt;堆的优势&lt;/strong&gt;： 虽然堆分配比栈分配开销大，但它允许变量在函数调用结束后继续存在。&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;4）&lt;strong&gt;如何逃逸分析&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;&lt;strong&gt;静态分析&lt;/strong&gt;： 编译器在编译过程中通过&lt;strong&gt;静态分析确定变量的生命周期&lt;/strong&gt;。它会检查变量是否在函数返回后仍然被引用，或者是否存储在全局变量或其他数据结构中，这些都会影响变量是否需要分配在堆上。&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;&lt;strong&gt;逃逸分析的例子&lt;/strong&gt;：&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;返回值&lt;/strong&gt;： 如果你从函数中返回一个局部变量（如&lt;strong&gt;切片或结构体&lt;/strong&gt;），这个变量会被分配到堆上，因为它的生命周期超出了函数调用的范围。&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;闭包&lt;/strong&gt;：如果一个局部变量被闭包引用，那么这个变量也会逃逸到堆上，因为闭包可能在函数调用结束后继续存在。&lt;/p&gt;&#xA;&lt;p&gt;代码示例：&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;package&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;main&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;fmt&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;kd&#34;&gt;func&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;main&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;// 1. 不会逃逸到堆&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;fmt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Println&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;// 2. 逃逸到堆&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;b&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;newSlice&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;// newSlice 返回一个切片，该切片的底层数组可能需要在堆上分配&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;fmt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Println&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;b&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;kd&#34;&gt;func&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;newSlice&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[]&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;int&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;s&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;make&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;([]&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;int&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;// s 是一个局部变量&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;s&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;append&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;s&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;return&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;s&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;// s 的底层数组会逃逸到堆上，因为切片在函数返回后仍然被引用&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;总结&lt;/strong&gt;&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
