pbytes.go 976 B

123456789101112131415161718192021222324
  1. // Package pbytes contains tools for pooling byte pool.
  2. // Note that by default it reuse slices with capacity from 128 to 65536 bytes.
  3. package pbytes
  4. // DefaultPool is used by pacakge level functions.
  5. var DefaultPool = New(128, 65536)
  6. // Get returns probably reused slice of bytes with at least capacity of c and
  7. // exactly len of n.
  8. // Get is a wrapper around DefaultPool.Get().
  9. func Get(n, c int) []byte { return DefaultPool.Get(n, c) }
  10. // GetCap returns probably reused slice of bytes with at least capacity of n.
  11. // GetCap is a wrapper around DefaultPool.GetCap().
  12. func GetCap(c int) []byte { return DefaultPool.GetCap(c) }
  13. // GetLen returns probably reused slice of bytes with at least capacity of n
  14. // and exactly len of n.
  15. // GetLen is a wrapper around DefaultPool.GetLen().
  16. func GetLen(n int) []byte { return DefaultPool.GetLen(n) }
  17. // Put returns given slice to reuse pool.
  18. // Put is a wrapper around DefaultPool.Put().
  19. func Put(p []byte) { DefaultPool.Put(p) }