Created
August 16, 2024 17:41
-
-
Save vinhjaxt/03d36d13fba5ed53988885630bd8c29d to your computer and use it in GitHub Desktop.
Golang bytes sync.pool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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