Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Builtin append vs. bytes.Buffer write

Tags:

People also ask

What is bytes buffer in go?

In go language, the buffer belongs to the byte package of the Go language, and we can use these package to manipulate the byte of the string. For example, suppose we have a string. We can read the length of the string with the len function, which will return the numeric length, but what if the strings are too large.

How do I create a byte buffer in Golang?

To create a byte in Go, assign an ASCII character to a variable. A byte in Golang is an unsigned 8-bit integer. The byte type represents ASCII characters, while the rune data type represents a broader set of Unicode characters encoded in UTF-8 format.


In the situation where I need to add an unknown amount of data to a slice of byte, let say in a loop, I could either way use the builtin function append() or create a new Buffer and use the Write() function.

Which method is fastest ?