You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
can add json.NewDecoderWithBytes function, use it like this:
var buffer bytes.Buffer
ch := make(chan io.Reader)
// .....
for _, reader := range ch {
buffer.Reset() // buffer is reused, redue gc
ioutil.Copy(buffer, reader)
dec := json.NewDecoderWithBytes(data)
dec.UseNumber()
dec.Decode(&m)
}
The text was updated successfully, but these errors were encountered:
Sorry, the above code was wrong.
var buffer bytes.Buffer
ch := make(chan io.Reader)
// .....
for _, reader := range ch {
buffer.Reset() // buffer is reused, redue gc
ioutil.Copy(buffer, reader)
dec := json.NewDecoderWithBytes(buffer.Bytes()) // This line of code above was wrong.
dec.UseNumber()
dec.Decode(&m)
}
use json.NewDecoder with bytes.NewReader, should copy all bytes to Decoder, it is what I
want to avoid。I want to reuse buffer and zero copy, Reducing the number of GC
by runner.mei:
The text was updated successfully, but these errors were encountered: