Comments (3)
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 []byte
from sync.Pool it is zeroed, but after that every other access may already have data in it.
also
fmt.Printf("#%+v", string(*bufp))
prints;
#
#hello
#hello
#
get 1 & 4 are okay(zeroed) but get 2 & 3 are not.
from meli.
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)
}
}
from meli.
see: golang/go#27740
from meli.
Related Issues (20)
- submit to awesome-go HOT 1
- support compose env_file HOT 1
- replace parsedotenv.env map with []string
- understand shell vars in volumes HOT 1
- key/value formatting is not supported HOT 2
- investigate how to get new docker client releases HOT 7
- high memory usage HOT 4
- Add to alpine apk
- use sub-tests
- add a --build flag
- volumes starting with .(dot) fail. HOT 1
- allow for .yaml as well as .yml docker-compose files
- test that it works in windows
- expand env vars in volumes
- meli -v fails
- links are linked wrongly
- Feature: add brew HOT 1
- add .env support HOT 4
- panic: runtime error: index out of range HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meli.