pool: return specified size of buffer

This commit is contained in:
nadoo committed 2020-04-19 23:20:15 +08:00
1 parent 5326c0a901
commit a0542a028e
16 files changed
+158 -139

No files matched your search

+3 -3
View File
@@ -29,14 +29,14 @@ var bufPools = [...]sync.Pool{
{New: func() interface{} { return make([]byte, 64<<10) }},
}
func GetBuffer(size int64) []byte {
func GetBuffer(size int) []byte {
i := 0
for ; i < len(bufSizes)-1; i++ {
if size <= int64(bufSizes[i]) {
if size <= bufSizes[i] {
break
}
}
return bufPools[i].Get().([]byte)
return bufPools[i].Get().([]byte)[:size]
}
func PutBuffer(p []byte) {
+1 -1
View File
@@ -9,7 +9,7 @@ var writeBufPool = sync.Pool{
New: func() interface{} { return &bytes.Buffer{} },
}
func GetWriteBuffer(size int64) *bytes.Buffer {
func GetWriteBuffer() *bytes.Buffer {
return writeBufPool.Get().(*bytes.Buffer)
}