-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reset items from sync.pool #118
Comments
if you run the following code: func BenchmarkPoolReadFrom(b *testing.B) {
r := strings.NewReader("hello")
b.ResetTimer()
for n := 0; n < 3; n++ {
_, _ = poolReadFrom(r)
}
} and inside Line 118 in 9e036d4
fmt.Printf("#%+v", bufp) you get an output like; #&[0 0 0 0 0 0 0 0]
#&[104 101 108 108 111 0 0 0]
#&[104 101 108 108 111 0 0 0]
#&[0 0 0 0 0 0 0 0]
#&[104 101 108 108 111 0 0 0] So the first time we get a fmt.Printf("#%+v", string(*bufp)) prints; #
#hello
#hello
# get 1 & 4 are okay(zeroed) but get 2 & 3 are not. |
package main
import (
"bytes"
"fmt"
"io"
"strings"
"sync"
)
const max = 512
var blackHolePool = sync.Pool{
New: func() interface{} {
return make([]byte, max)
},
}
func main() {
x := []string{"hello", "cool", "three", "four"}
for _, v := range x {
src := strings.NewReader(v)
bufp := blackHolePool.Get().([]byte)
dst := bytes.NewBuffer(bufp)
io.Copy(dst, src)
blackHolePool.Put(bufp[:max])
fmt.Println(dst)
}
} |
see: golang/go#27740 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
we should reset whatever we get from sync.pool b4 use;
meli/image.go
Line 118 in 9e036d4
The text was updated successfully, but these errors were encountered: