Skip to content

Instantly share code, notes, and snippets.

@vinhjaxt
Created August 16, 2024 17:41
Show Gist options
  • Save vinhjaxt/03d36d13fba5ed53988885630bd8c29d to your computer and use it in GitHub Desktop.
Save vinhjaxt/03d36d13fba5ed53988885630bd8c29d to your computer and use it in GitHub Desktop.
Golang bytes sync.pool
var buffer8kPool sync.Pool = sync.Pool{
New: func() interface{} {
v := make([]byte, 8*1024)
return &v
},
}
func getBuffer8k() *[]byte {
return buffer8kPool.Get().(*[]byte)
}
func putBuffer8k(b *[]byte) {
*b = (*b)[:cap(*b)]
buffer8kPool.Put(b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment