added preload and streaming buffer pool
This commit is contained in:
parent
cd0b0254c7
commit
b010b3a93e
5 changed files with 70 additions and 20 deletions
27
pkg/fs/pool.go
Normal file
27
pkg/fs/pool.go
Normal 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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue