github.com/grailbio/base@v0.0.11/file/internal/s3bufpool/s3bufpool.go (about) 1 package s3bufpool 2 3 import ( 4 "sync" 5 ) 6 7 var ( 8 BufBytes = 16 * 1024 * 1024 9 pool = sync.Pool{ 10 New: func() any { 11 b := make([]byte, BufBytes) 12 // Note: Return *[]byte, not []byte, so there's one heap allocation now to create the 13 // interface value, rather than one per Put. 14 return &b 15 }, 16 } 17 ) 18 19 func Get() *[]byte { return pool.Get().(*[]byte) } 20 func Put(b *[]byte) { pool.Put(b) } 21 22 // SetBufSize modifies the buffer size. It's for testing only, and callers are responsible for 23 // making sure there's no race with Get or Put. 24 func SetBufSize(bytes int) { 25 BufBytes = bytes 26 pool = sync.Pool{New: pool.New} // Empty the pool. 27 }