Jason
5 years ago
4 changed files with 29 additions and 6 deletions
@ -0,0 +1,23 @@ |
|||
package core |
|||
|
|||
import ( |
|||
"sync" |
|||
) |
|||
|
|||
const defaultBufferSize = 2 * 1024 |
|||
|
|||
var bufPool = sync.Pool{New: func() interface{} { return make([]byte, defaultBufferSize) }} |
|||
|
|||
func newBytes(size int) []byte { |
|||
if size <= defaultBufferSize { |
|||
return bufPool.Get().([]byte) |
|||
} else { |
|||
return make([]byte, size) |
|||
} |
|||
} |
|||
|
|||
func freeBytes(b []byte) { |
|||
if len(b) >= defaultBufferSize { |
|||
bufPool.Put(b) |
|||
} |
|||
} |
Loading…
Reference in new issue