Probably I was doing something wrong. @Brian your snippet works as I would have expected.
On Friday, 12 June 2020 15:43:14 UTC+5:30, Brian Candler wrote: > > However, it does say "The new Buffer takes ownership of buf" - why would > it do that if it were allocating a new buffer and taking a copy of the > original? > > The code has the answer, it's just a single line: > https://golang.org/src/bytes/buffer.go?s=14279:14313#L440 > > func NewBuffer(buf []byte) *Buffer { return &Buffer{buf: buf} } > > > ISTM that the Buffer object is simply using the buf you provided. I don't > understand where the claim comes from that (a) it allocates a buffer, and > (b) the allocated buffer is of size 4096 bytes. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/72bea30b-7223-4f59-aa0d-c6c820026e99o%40googlegroups.com.