You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
450 B
Go

package utils
import "sync"
type ByteSlice struct {
B []byte
}
var (
byteSlicePool = sync.Pool{
New: func() interface{} {
return new(ByteSlice)
},
}
)
func ByteSliceGet(length int) *ByteSlice {
data := byteSlicePool.Get().(*ByteSlice)
if cap(data.B) < length {
data.B = make([]byte, length)
} else {
data.B = data.B[:length]
}
return data
}
func ByteSlicePut(data *ByteSlice) {
data.B = data.B[:0]
byteSlicePool.Put(data)
}