Skip to content

Commit

Permalink
Moves buffer pool to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
ksysoev committed Apr 20, 2024
1 parent 99faff9 commit e8f2b65
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions channel/buffers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package channel

import (
"bytes"
"sync"
)

type bufferPool struct {
pool *sync.Pool
}

func newBufferPool() *bufferPool {
return &bufferPool{
pool: &sync.Pool{
New: func() interface{} {
return &bytes.Buffer{}
},
},
}
}

func (p *bufferPool) get() *bytes.Buffer {
return p.pool.Get().(*bytes.Buffer)
}

func (p *bufferPool) put(b *bytes.Buffer) {
b.Reset()
p.pool.Put(b)
}

0 comments on commit e8f2b65

Please sign in to comment.