buffer_pool.go

package nsqd

import (
    "bytes"
    "sync"
)

var bp sync.Pool

func init() {
    bp.New = func() interface{} {
        return &bytes.Buffer{}
    }
}

func bufferPoolGet() *bytes.Buffer {
    return bp.Get().(*bytes.Buffer)
}

func bufferPoolPut(b *bytes.Buffer) {
    bp.Put(b)
}

原文地址:https://www.cnblogs.com/zhangboyu/p/7457249.html