github.com/trim21/go-phpserialize@v0.0.22-0.20240301204449-2fca0319b3f0/internal/encoder/buffer.go (about) 1 package encoder 2 3 import "sync" 4 5 type buffer struct { 6 b []byte 7 } 8 9 var bufferPool = sync.Pool{New: func() any { 10 return &buffer{b: make([]byte, 0, 1024)} 11 }} 12 13 func newBuffer() *buffer { 14 buf := bufferPool.Get().(*buffer) 15 buf.b = buf.b[:0] 16 17 return buf 18 } 19 20 func freeBuffer(buf *buffer) { 21 bufferPool.Put(buf) 22 }