github.com/iikira/iikira-go-utils@v0.0.0-20230610031953-f2cb11cde33a/utils/cachepool/syncpool.go (about) 1 package cachepool 2 3 import ( 4 "github.com/iikira/iikira-go-utils/utils/converter" 5 "runtime" 6 "sync" 7 ) 8 9 var ( 10 syncPoolSize = int(64 * converter.KB) 11 syncPoolFirstNew = false 12 SyncPool = sync.Pool{ 13 New: func() interface{} { 14 syncPoolFirstNew = true 15 return RawMallocByteSlice(syncPoolSize) 16 }, 17 } 18 ) 19 20 func SetSyncPoolSize(size int) { 21 if syncPoolFirstNew && size != syncPoolSize { 22 runtime.GC() 23 } 24 syncPoolSize = size 25 }