Change BuffSizeCopy pool

This commit is contained in:
ffdfgdfg
2019-08-26 23:29:22 +08:00
parent 4bb7e33b16
commit 53c2e472ae
5 changed files with 39 additions and 10 deletions

View File

@@ -59,6 +59,27 @@ func PutBufPoolMax(buf []byte) {
}
}
type CopyBufferPool struct {
pool sync.Pool
}
func (Self *CopyBufferPool) New() {
Self.pool = sync.Pool{
New: func() interface{} {
return make([]byte, PoolSizeCopy)
},
}
}
func (Self *CopyBufferPool) Get() []byte {
return Self.pool.Get().([]byte)
}
func (Self *CopyBufferPool) Put(x []byte) {
x = x[:0]
Self.pool.Put(x)
}
type BufferPool struct {
pool sync.Pool
}
@@ -82,7 +103,13 @@ func (Self *BufferPool) Put(x *bytes.Buffer) {
var once = sync.Once{}
var BuffPool = BufferPool{}
var CopyBuff = CopyBufferPool{}
func newPool() {
BuffPool.New()
CopyBuff.New()
}
func init() {
once.Do(BuffPool.New)
once.Do(newPool)
}