github.com/fzfile/BaiduPCS-Go@v0.0.0-20200606205115-4408961cf336/pcsutil/cachepool/syncpool.go (about)

     1  package cachepool
     2  
     3  import (
     4  	"github.com/fzfile/BaiduPCS-Go/pcsutil/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  }