Put releases byte buffer obtained via Get to the pool. The buffer mustn't be accessed after returning to the pool.
(b *ByteBuffer)
| 65 | // |
| 66 | // The buffer mustn't be accessed after returning to the pool. |
| 67 | func (p *Pool) Put(b *ByteBuffer) { |
| 68 | idx := index(len(b.B)) |
| 69 | |
| 70 | if atomic.AddUint64(&p.calls[idx], 1) > calibrateCallsThreshold { |
| 71 | p.calibrate() |
| 72 | } |
| 73 | |
| 74 | maxSize := int(atomic.LoadUint64(&p.maxSize)) |
| 75 | if maxSize == 0 || cap(b.B) <= maxSize { |
| 76 | b.Reset() |
| 77 | p.pool.Put(b) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | func (p *Pool) calibrate() { |
| 82 | if !atomic.CompareAndSwapUint64(&p.calibrating, 0, 1) { |