Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro committed Feb 13, 2025
1 parent b7700d8 commit b8fc8b4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/utils/dynamic_alloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,26 @@ func DynAlloc(size int) []byte {
return b[:size]
}

// DynFree b may be longer than the original, in the actual size into the pool
func DynFree(b []byte) {
dynPools[powerOf2(cap(b))].Put(&b)
dynPools[FloorPowerOf2(cap(b))].Put(&b)
}

func FloorPowerOf2(s int) int {
var bits int
var p = 1
for p <= s {
bits++
p *= 2
}
return bits - 1
}

var dynPools []*sync.Pool

func init() {
dynPools = make([]*sync.Pool, 33) // 1 - 8G
for i := 0; i < 33; i++ {
dynPools = make([]*sync.Pool, 34) // 1 - 8G
for i := 0; i < 34; i++ {
func(bits int) {
dynPools[i] = &sync.Pool{
New: func() interface{} {
Expand Down

0 comments on commit b8fc8b4

Please sign in to comment.