init: v1.0.0

This commit is contained in:
yaole
2026-05-27 23:03:00 +08:00
commit 8d97f750eb
466 changed files with 80067 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
/*
pool is pool of tmp obj
临时对象的存储,每次GC都可能会回收。
*/
package objectpool
import (
"math/big"
"sync"
)
// BytePool is pool for []byte
var BytePool = sync.Pool{
New: func() interface{} {
b := make([]byte, 0, 1024)
return &b
},
}
var SmallBytePool = sync.Pool{
New: func() interface{} {
b := make([]byte, 0, 256)
return &b
},
}
var LargeBytePool = sync.Pool{
New: func() interface{} {
b := make([]byte, 0, 4096)
return &b
},
}
// GetBytes wraps the pool, for clear data
func GetBytes() []byte {
b := BytePool.Get().(*[]byte)
return (*b)[:0]
}
func PutBytes(b []byte) {
BytePool.Put(&b)
}
func GetSmallBytes() []byte {
b := SmallBytePool.Get().(*[]byte)
return (*b)[:0]
}
func PutSmallBytes(b []byte) {
BytePool.Put(&b)
}
func GetLargeBytes() []byte {
b := LargeBytePool.Get().(*[]byte)
return (*b)[:0]
}
func PutLargeBytes(b []byte) {
BytePool.Put(&b)
}
// BigIntPool is pool for Big.Int
var BigIntPool = sync.Pool{
New: func() interface{} {
b := new(big.Int)
return b
},
}
func GetBigInt() *big.Int {
b := BigIntPool.Get().(*big.Int)
b.SetInt64(0)
return b
}
func PutBigInt(b *big.Int) {
BigIntPool.Put(b)
}