cloudflare/cloudflared

Public

mirrored fromhttps://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0c65daaa7dbb66e16d8716abcb9684fc81988263

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

buffer/pool.go

29lines · modecode

1package buffer
2
3import (
4 "sync"
5)
6
7type Pool struct {
8 // A Pool must not be copied after first use.
9 // https://golang.org/pkg/sync/#Pool
10 buffers sync.Pool
11}
12
13func NewPool(bufferSize int) *Pool {
14 return &Pool{
15 buffers: sync.Pool{
16 New: func() interface{} {
17 return make([]byte, bufferSize)
18 },
19 },
20 }
21}
22
23func (p *Pool) Get() []byte {
24 return p.buffers.Get().([]byte)
25}
26
27func (p *Pool) Put(buf []byte) {
28 p.buffers.Put(buf)
29}
30