cloudflare/cloudflared

Public

mirrored from https://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2020.8.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

buffer/pool.go

29lines · modeblame

464bb530Rueian6 years ago1package 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
10buffers sync.Pool
11}
12
13func NewPool(bufferSize int) *Pool {
14return &Pool{
15buffers: sync.Pool{
16New: func() interface{} {
17return make([]byte, bufferSize)
18},
19},
20}
21}
22
23func (p *Pool) Get() []byte {
24return p.buffers.Get().([]byte)
25}
26
27func (p *Pool) Put(buf []byte) {
28p.buffers.Put(buf)
29}