github.com/tickstep/library-go@v0.1.1/cachepool/syncpool.go (about)

     1  package cachepool
     2  
     3  import (
     4  	"github.com/tickstep/library-go/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  }