I'd like to know the proper way to reuse the []byte buffer in go. I declare it like this
buf := make([]byte, 1024)
and then use like this
conn, _ := net.Dial("tcp", addr)
_, err = conn.read(buf)
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)?