mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
pool: return specified size of buffer
This commit is contained in:
1 parent
5326c0a901
commit
a0542a028e
16 files changed
+158
-139
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user