1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-03 07:45:29 -05:00
This commit is contained in:
Darien Raymond
2018-12-03 23:39:21 +01:00
parent 28fa84ce69
commit a6d81cc56d
3 changed files with 14 additions and 0 deletions

View File

@@ -35,6 +35,8 @@ func init() {
// GetPool returns a sync.Pool that generates bytes array with at least the given size.
// It may return nil if no such pool exists.
//
// v2ray:api:stable
func GetPool(size int32) *sync.Pool {
for idx, ps := range poolSize {
if size <= ps {
@@ -45,6 +47,8 @@ func GetPool(size int32) *sync.Pool {
}
// Alloc returns a byte slice with at least the given size. Minimum size of returned slice is 2048.
//
// v2ray:api:stable
func Alloc(size int32) []byte {
pool := GetPool(size)
if pool != nil {
@@ -54,6 +58,8 @@ func Alloc(size int32) []byte {
}
// Free puts a byte slice into the internal pool.
//
// v2ray:api:stable
func Free(b []byte) {
size := int32(cap(b))
b = b[0:cap(b)]