pool.go 663 B

12345678910111213141516171819202122232425
  1. // Package pool contains helpers for pooling structures distinguishable by
  2. // size.
  3. //
  4. // Quick example:
  5. //
  6. // import "github.com/gobwas/pool"
  7. //
  8. // func main() {
  9. // // Reuse objects in logarithmic range from 0 to 64 (0,1,2,4,6,8,16,32,64).
  10. // p := pool.New(0, 64)
  11. //
  12. // buf, n := p.Get(10) // Returns buffer with 16 capacity.
  13. // if buf == nil {
  14. // buf = bytes.NewBuffer(make([]byte, n))
  15. // }
  16. // defer p.Put(buf, n)
  17. //
  18. // // Work with buf.
  19. // }
  20. //
  21. // There are non-generic implementations for pooling:
  22. // - pool/pbytes for []byte reuse;
  23. // - pool/pbufio for *bufio.Reader and *bufio.Writer reuse;
  24. //
  25. package pool