Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
func NewBufferPool ¶
func NewBufferPool(left, right uint32) *BufferPool
NewBufferPool 创建一个内存池,复制自 `https://github.com/lxzan/gws/blob/main/internal/pool.go`
e.g. NewBufferPool(16, 200): &{16 65536 map[16:0xc000ad5bc0 32:0xc000ad5bf0 64:0xc000ad5c20 128:0xc000ad5c50 256:0xc000ad5c80]}
creates a memory pool left 和 right 表示内存池的区间范围,它们将被转换为 2 的 n 次幂 left and right indicate the interval range of the memory pool, they will be transformed into pow(2, n) 小于 left 的情况下,Get 方法将返回至少 left 字节的缓冲区;大于 right 的情况下,Put 方法不会回收缓冲区 Below left, the Get method will return at least left bytes; above right, the Put method will not reclaim the buffer
func (*BufferPool) Get ¶
func (p *BufferPool) Get(n int) *bytes.Buffer
Get 从内存池中获取一个至少 n 字节的缓冲区 fetches a buffer from the memory pool, of at least n bytes
func (*BufferPool) Put ¶
func (p *BufferPool) Put(b *bytes.Buffer)
Put 将缓冲区放回到内存池 returns the buffer to the memory pool