<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Bytes.Buffer on 小惡魔 - AppleBOY</title><link>https://blog.wu-boy.com/tags/bytes.buffer/</link><description>Recent content in Bytes.Buffer on 小惡魔 - AppleBOY</description><generator>Hugo</generator><language>en-us</language><managingEditor>appleboy.tw@gmail.com (Appleboy)</managingEditor><webMaster>appleboy.tw@gmail.com (Appleboy)</webMaster><lastBuildDate>Tue, 07 Jun 2022 20:42:17 +0800</lastBuildDate><atom:link href="https://blog.wu-boy.com/tags/bytes.buffer/feed.xml" rel="self" type="application/rss+xml"/><item><title>在 Go 語言內使用 bytes.Buffer 注意事項</title><link>https://blog.wu-boy.com/2022/06/reuse-the-bytes-buffer-in-go/</link><pubDate>Tue, 07 Jun 2022 20:42:17 +0800</pubDate><author>appleboy.tw@gmail.com (Appleboy)</author><guid>https://blog.wu-boy.com/2022/06/reuse-the-bytes-buffer-in-go/</guid><description>&lt;p&gt;&lt;img src="https://i.imgur.com/FD5go1t.png" alt="logo"&gt;&lt;/p&gt;
&lt;p&gt;在 &lt;a href="https://go.dev"&gt;Go 語言&lt;/a&gt;中，如何高效的處理字串相加，由於字串 (string) 是不可變的，所以將很多字串拼接起來，會如同宣告新的變數來儲存。這邊就可以透過 &lt;a href="https://pkg.go.dev/strings"&gt;strings.Builder&lt;/a&gt; 或 &lt;a href="https://pkg.go.dev/bytes"&gt;bytes.Buffer&lt;/a&gt; 來解決字串相加效能問題。除了效能問題之外，還需要注意在 &lt;code&gt;bytes.Buffer&lt;/code&gt; 處理 &lt;code&gt;[]byte&lt;/code&gt; 及 &lt;code&gt;string&lt;/code&gt; 之間的轉換，底下拿實際專案上寫出來的錯誤給大家參考看看&lt;/p&gt;</description></item></channel></rss>