Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <[email protected]>
  • Loading branch information
hawkingrei committed Mar 14, 2024
1 parent b7f5eaa commit e903390
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions internal/client/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ type simpleSharedBufferPool struct {
}

func (p *simpleSharedBufferPool) Get(size int) []byte {
return p.pools[p.poolIdx(size)].Get(size)
idx := p.poolIdx(size)
if idx == levelMaxPoolIdx {
return make([]byte, size)
}
return p.pools[idx].Get(size)
}

func (p *simpleSharedBufferPool) Put(bs *[]byte) {
p.pools[p.poolIdx(cap(*bs))].Put(bs)
idx := p.poolIdx(cap(*bs))
if idx == levelMaxPoolIdx {
return
}
p.pools[idx].Put(bs)
}

func (p *simpleSharedBufferPool) poolIdx(size int) int {
Expand All @@ -69,7 +77,7 @@ const (
level1PoolMaxSize = level0PoolMaxSize * 16 // 256 B
level2PoolMaxSize = level1PoolMaxSize * 16 // 4 KB
level3PoolMaxSize = level2PoolMaxSize * 16 // 64 KB
level4PoolMaxSize = level3PoolMaxSize * 16 // 1 MB
level4PoolMaxSize = level3PoolMaxSize * 2 // 128 MB
)

const (
Expand Down

0 comments on commit e903390

Please sign in to comment.