MCPcopy Create free account
hub / github.com/valyala/bytebufferpool / Put

Method Put

pool.go:67–79  ·  view source on GitHub ↗

Put releases byte buffer obtained via Get to the pool. The buffer mustn't be accessed after returning to the pool.

(b *ByteBuffer)

Source from the content-addressed store, hash-verified

65//
66// The buffer mustn't be accessed after returning to the pool.
67func (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
81func (p *Pool) calibrate() {
82 if !atomic.CompareAndSwapUint64(&p.calibrating, 0, 1) {

Callers 2

ExampleByteBufferFunction · 0.80
PutFunction · 0.80

Calls 3

calibrateMethod · 0.95
indexFunction · 0.85
ResetMethod · 0.80

Tested by 1

ExampleByteBufferFunction · 0.64