pools.go 827 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Public Domain Software
  3. *
  4. * I (Matthias Ladkau) am the author of the source code in this file.
  5. * I have placed the source code in this file in the public domain.
  6. *
  7. * For further information see: http://creativecommons.org/publicdomain/zero/1.0/
  8. */
  9. /*
  10. Package pools contains object pooling utilities.
  11. */
  12. package pools
  13. import (
  14. "bytes"
  15. "sync"
  16. )
  17. /*
  18. NewByteBufferPool creates a new pool of bytes.Buffer objects. The pool creates
  19. new ones if it runs empty.
  20. */
  21. func NewByteBufferPool() *sync.Pool {
  22. return &sync.Pool{New: func() interface{} { return &bytes.Buffer{} }}
  23. }
  24. /*
  25. NewByteSlicePool creates a new pool of []byte objects of a certain size. The
  26. pool creates new ones if it runs empty.
  27. */
  28. func NewByteSlicePool(size int) *sync.Pool {
  29. return &sync.Pool{New: func() interface{} { return make([]byte, size) }}
  30. }