Skip to content

Commit

Permalink
新增big pool, 后续版本优化下
Browse files Browse the repository at this point in the history
  • Loading branch information
guonaihong committed May 19, 2024
1 parent da4c929 commit c3ac38c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 66 deletions.
39 changes: 39 additions & 0 deletions bytespool/bytes_big_buf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2023-2024 antlabs. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package bytespool

import "sync"

// TODO: 启用, 目前暂未使用
var bigPool = sync.Pool{
New: func() interface{} {
buf := make([]byte, 0, 1024*256)
return &buf
},
}

func getBigPayload(n int) (rv *[]byte) {
rv = bigPool.Get().(*[]byte)
if cap(*rv) < n {
tmp := make([]byte, n)
*rv = tmp
} else {
*rv = (*rv)[:n]
}
return rv
}

func putBigPayload(buf *[]byte) {
bigPool.Put(buf)
}
66 changes: 0 additions & 66 deletions bytespool/bytes_pool_noarena_test.go

This file was deleted.

0 comments on commit c3ac38c

Please sign in to comment.