This commit is contained in:
Lei Xue
2017-08-02 19:01:41 +08:00
parent 4ae643e9f8
commit fcb96b323d
6 changed files with 91 additions and 101 deletions

View File

@@ -19,12 +19,16 @@ package pool
import "sync"
var bytePool sync.Pool = sync.Pool{}
func NewBuffer(size int) []byte {
var bytePool = sync.Pool{
New: func() interface{} {
return make([]byte, size)
},
bytePool.New = func() interface{} {
return make([]byte, size)
}
return bytePool.Get().([]byte)
}
func ReleaseBuffer(b []byte) {
bytePool.Put(b)
}