1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-17 23:06:30 -05:00

reduce number of preallocated buffers

This commit is contained in:
Darien Raymond 2016-02-02 10:52:23 +00:00
parent 159644a230
commit 50007a9790

View File

@ -128,7 +128,7 @@ func newBufferPool(bufferSize, poolSize int) *bufferPool {
New: func() interface{} { return make([]byte, bufferSize) }, New: func() interface{} { return make([]byte, bufferSize) },
}, },
} }
for i := 0; i < poolSize; i++ { for i := 0; i < poolSize / 2; i++ {
pool.chain <- make([]byte, bufferSize) pool.chain <- make([]byte, bufferSize)
} }
return pool return pool
@ -157,9 +157,9 @@ func (p *bufferPool) free(buffer *Buffer) {
} }
} }
var smallPool = newBufferPool(1024, 256) var smallPool = newBufferPool(1024, 64)
var mediumPool = newBufferPool(8*1024, 512) var mediumPool = newBufferPool(8*1024, 128)
var largePool = newBufferPool(64*1024, 128) var largePool = newBufferPool(64*1024, 64)
// NewSmallBuffer creates a Buffer with 1K bytes of arbitrary content. // NewSmallBuffer creates a Buffer with 1K bytes of arbitrary content.
func NewSmallBuffer() *Buffer { func NewSmallBuffer() *Buffer {