reusing read buffers when working with sockets
<p>I'd like to know the proper way to reuse the []byte buffer in go. I declare it like this</p>

<pre><code>buf := make([]byte, 1024)
</code></pre>

<p>and then use like this</p>

<pre><code>conn, _ := net.Dial("tcp", addr)
_, err = conn.read(buf)
</code></pre>

<p>I heard that declaring a new buffer isn't efficient since it involves memory allocations and that we should reuse existing buffers instead. However I am not sure if I just can pass the buffer again and it will be wiped or it can hold parts of previous messages (especially if the current message from socket is shorter than prev.one)?</p>