8000 Update sync_pool.go by zonesowhat · Pull Request #4 · funny/slab · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update sync_pool.go #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions sync_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ func NewSyncPool(minSize, maxSize, factor int) *SyncPool {
}

// Alloc try alloc a []byte from internal slab class if no free chunk in slab class Alloc will make one.
func (pool *SyncPool) Alloc(size int) []byte {
// 1st returned value indicate a slice caller can use
// 2nd returned value indicate the capacity of the slice
// 3rd returned value indicate whether the slice is allocated from this pool or not
func (pool *SyncPool) Alloc(size int) ([]byte, int, bool) {
if size <= pool.maxSize {
for i := 0; i < len(pool.classesSize); i++ {
if pool.classesSize[i] >= size {
mem := pool.classes[i].Get().(*[]byte)
return (*mem)[:size]
return (*mem)[:size], pool.classesSize[i], true
}
}
}
return make([]byte, size)
return make([]byte, size), size, false
}

// Free release a []byte that alloc from Pool.Alloc.
Expand Down
0