added preload and streaming buffer pool

This commit is contained in:
ston1th 2022-08-19 19:01:28 +02:00
commit b010b3a93e
5 changed files with 70 additions and 20 deletions

27
pkg/fs/pool.go Normal file
View file

@ -0,0 +1,27 @@
// Copyright (C) 2022 Marius Schellenberger
package fs
import (
"sync"
)
type pool[T any] struct {
p sync.Pool
}
func newPool[T any](newf func() T) *pool[T] {
return &pool[T]{
p: sync.Pool{
New: func() any { return newf() },
},
}
}
func (p *pool[T]) Get() T {
return p.p.Get().(T)
}
func (p *pool[T]) Put(v T) {
p.p.Put(v)
}