内存优化

This commit is contained in:
刘河
2019-01-13 22:02:58 +08:00
parent 72290275cc
commit 53e57ea70d
3 changed files with 10 additions and 18 deletions

View File

@@ -147,15 +147,14 @@ func GetIntNoerrByStr(str string) int {
// io.copy的优化版读取buffer长度原为32*1024与snappy不同导致读取出的内容存在差异不利于解密特此修改
//废除
//内存优化 用到pool快速回收
func copyBuffer(dst io.Writer, src io.Reader) (written int64, err error) {
//TODO 回收问题
buf := bufPoolCopy.Get().([]byte)
defer bufPoolCopy.Put(buf)
for {
buf := bufPoolCopy.Get().([]byte)
nr, er := src.Read(buf)
if nr > 0 {
nw, ew := dst.Write(buf[0:nr])
bufPoolCopy.Put(buf)
if nw > 0 {
written += int64(nw)
}
@@ -167,6 +166,8 @@ func copyBuffer(dst io.Writer, src io.Reader) (written int64, err error) {
err = io.ErrShortWrite
break
}
}else {
bufPoolCopy.Put(buf)
}
if er != nil {
if er != io.EOF {