Documentation ¶
Overview ¶
Package pool 创建一些常用的 pool, 底层依托 sync.pool
在项目开发中会大量使用 sync.Pool, 有很多 pool 是可以共享的,最常见的就是 bytes.Buffer。 大量的开源库中在使用 bytes.Buffer 的 sync.Pool, 每个项目单独维护自己的 sync.Pool, 使得很多资源没有被合理的利用, 造成大量的浪费,这个包收集常见的 sync.Pool 实例,使其可以在不同项目和包中可以共享。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufferPool ¶
type BufferPool interface { // Get 从 Pool 中获取一个 *bytes.Buffer 实例, 该实例已经被 Reset Get() *bytes.Buffer // Put 把 *bytes.Buffer 放回 Pool 中 Put(*bytes.Buffer) }
BufferPool bytes.Buffer 的 sync.Pool 接口 可以直接 Get *bytes.Buffer 并 Reset Buffer
func NewBuffer ¶ added in v1.3.0
func NewBuffer(size int) BufferPool
NewBuffer 创建一个指定容量的 BufferPool,这将是一个独立的非共享的,每次调用都会返回新的BufferPool
Click to show internal directories.
Click to hide internal directories.