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

20 lines
291 B

  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. }