Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer represents the reuse buffer.
func (*Buffer) AllocBytes ¶
AllocBytes allocates bytes with the given length.
type Option ¶
type Option func(p *Pool)
Option configures a pool.
func WithAllocator ¶
WithAllocator specifies the allocator used by pool to allocate and free memory.
func WithBlockSize ¶
WithBlockSize configures the size of each block.
func WithLargeAllocThreshold ¶
WithLargeAllocThreshold configures the threshold for large allocation of a Buffer. If allocate size is larger than this threshold, bytes will be allocated directly by the make built-in function and won't be tracked by the pool.
func WithPoolSize ¶
WithPoolSize configures how many blocks cached by this pool.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is like `sync.Pool`, which manages memory for all bytes buffers.
NOTE: we don't used a `sync.Pool` because when will sync.Pool release is depending on the garbage collector which always release the memory so late. Use a fixed size chan to reuse can decrease the memory usage to 1/3 compare with sync.Pool.