sync_pool.go 291 B

1234567891011121314151617181920
  1. package buffer_pool
  2. import (
  3. "bytes"
  4. "sync"
  5. )
  6. var syncPool = sync.Pool{
  7. New: func() interface{} {
  8. return new(bytes.Buffer)
  9. },
  10. }
  11. func SyncPoolGetBuffer() *bytes.Buffer {
  12. return syncPool.Get().(*bytes.Buffer)
  13. }
  14. func SyncPoolPutBuffer(buffer *bytes.Buffer) {
  15. syncPool.Put(buffer)
  16. }