NewSizedBufferPool creates a new BufferPool bounded to the given size. size defines the number of buffers to be retained in the pool and alloc sets the initial capacity of new buffers to minimize calls to make(). The value of alloc should seek to provide a buffer that is representative of most data
(size int, alloc int)
| 24 | // track the capacity of your last N buffers (i.e. using an []int) prior to |
| 25 | // returning them to the pool as input into calculating a suitable alloc value. |
| 26 | func NewSizedBufferPool(size int, alloc int) (bp *SizedBufferPool) { |
| 27 | return &SizedBufferPool{ |
| 28 | c: make(chan *bytes.Buffer, size), |
| 29 | a: alloc, |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | // Get gets a Buffer from the SizedBufferPool, or creates a new one if none are |
| 34 | // available in the pool. Buffers have a pre-allocated capacity. |
no outgoing calls
searching dependent graphs…