Sorry for my explanations. I wanted to mean that when i use a len([]byte) <=16384 the program can read lots of megabytes and remains at a stable state of memory usage, 5 mb.
When i use higher values, the memory grows and keep growing. by higher value i mean anything > 16384 The slice is valid for use only until the next buffer > modification (that is, only until the next call to a method like Read, > Write, Reset, or Truncate). The slice aliases the buffer content at > least until the next buffer modification, so immediate changes to the > slice will affect the result of future reads. > Indeed, if i write some data on buf, i see the changes in r. r := buf.Bytes() // read from encoder fmt.Println(r) buf.Truncate(0) buf.Write([]byte("aaaaaaaaaaa")) fmt.Println("_______") fmt.Println(r) I thought it was a copy. But now i don't understand why Truncate(0) does not erase r, as in https://golang.org/src/bytes/buffer.go?s=2594:2626#L57 there is this b.buf = b.buf[0 : b.off+n] Which resolves to b.buf = b.buf[0:0] :x Le dimanche 3 juillet 2016 21:08:01 UTC+2, Janne Snabb a écrit : > > On 2016-07-03 20:35, mhhcbon wrote: > > > r :=buf.Bytes()// read from encoder > > buf.Truncate(0) > > > I did not understand your explanation of the problem, but surely there > is a bug in the code quoted above. > > Read bytes.Buffer Bytes() function documentation: > > func (b *Buffer) Bytes() []byte > > Bytes returns a slice of length b.Len() holding the unread portion of > the buffer. The slice is valid for use only until the next buffer > modification (that is, only until the next call to a method like Read, > Write, Reset, or Truncate). The slice aliases the buffer content at > least until the next buffer modification, so immediate changes to the > slice will affect the result of future reads. > > > Janne Snabb > sn...@epipe.com <javascript:> > > -- 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. For more options, visit https://groups.google.com/d/optout.