Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ObjectPool ¶
type ObjectPool[T any] struct { // contains filtered or unexported fields }
ObjectPool 基于 sync.Pool 实现的线程安全的对象池
- 一些高频临时生成使用的对象可以通过 ObjectPool 进行管理,例如属性计算等
func NewObjectPool ¶
func NewObjectPool[T any](generator func() *T, releaser func(data *T)) *ObjectPool[*T]
NewObjectPool 创建一个 ObjectPool
Example ¶
package main import ( "fmt" "github.com/kercylan98/minotaur/utils/collection" "github.com/kercylan98/minotaur/utils/hub" ) func main() { var p = hub.NewObjectPool[map[int]int](func() *map[int]int { return &map[int]int{} }, func(data *map[int]int) { collection.ClearMap(*data) }) m := *p.Get() m[1] = 1 p.Release(&m) fmt.Println(m) }
Output: map[]
Click to show internal directories.
Click to hide internal directories.