xbuffer

package
v1.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

README

xbuffer

  1. BufferPool Based on sync.Pool, sync.Pool automatically GC's objects.

  2. SizedBufferPool Based channel, creates a new BufferPool bounded to the given size. objects in this pool are alive along with the application life cycle.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferPool

type BufferPool struct {
	// contains filtered or unexported fields
}

BufferPool buffer pool definition

func NewBufferPool

func NewBufferPool(alloc int) *BufferPool

NewBufferPool creates a new BufferPool bounded to the given buffer size.

func (*BufferPool) Get

func (bp *BufferPool) Get() *bytes.Buffer

Get gets a Buffer from the BufferPool

func (*BufferPool) Put

func (bp *BufferPool) Put(buffer *bytes.Buffer)

Put returns the given Buffer to the BufferPool

type SizedBufferPool

type SizedBufferPool struct {
	// contains filtered or unexported fields
}

SizedBufferPool sized buffer pool definition

func NewSizedBufferPool

func NewSizedBufferPool(size int, alloc int) (bp *SizedBufferPool)

SizedBufferPool creates a new BufferPool bounded to the given size. size defines the number of buffers to be retained in the pool and alloc sets the initial capacity of new buffers to minimize calls to make().

The value of alloc should seek to provide a buffer that is representative of most data written to the the buffer (i.e. 95th percentile) without being overly large (which will increase static memory consumption).

func (*SizedBufferPool) Get

func (bp *SizedBufferPool) Get() (b *bytes.Buffer)

Get gets a Buffer from the SizedBufferPool, or creates a new one if none are available in the pool. Buffers have a pre-allocated capacity.

func (*SizedBufferPool) Put

func (bp *SizedBufferPool) Put(b *bytes.Buffer)

Put returns the given Buffer to the SizedBufferPool.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL