pool

package
v1.48.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package pool implements a memory pool similar in concept to sync.Pool but with more determinism.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool of internal buffers

We hold buffers in cache. Every time we Get or Put we update minFill which is the minimum len(cache) seen.

Every flushTime we remove minFill buffers from the cache as they were not used in the previous flushTime interval.

func New

func New(flushTime time.Duration, bufferSize, poolSize int, useMmap bool) *Pool

New makes a buffer pool

flushTime is the interval the buffer pools is flushed bufferSize is the size of the allocations poolSize is the maximum number of free buffers in the pool useMmap should be set to use mmap allocations

func (*Pool) Alloced

func (bp *Pool) Alloced() int

Alloced returns the number of buffers allocated and not yet freed

func (*Pool) Flush

func (bp *Pool) Flush()

Flush the entire buffer pool

func (*Pool) Get

func (bp *Pool) Get() []byte

Get a buffer from the pool or allocate one

func (*Pool) InPool

func (bp *Pool) InPool() int

InPool returns the number of buffers in the pool

func (*Pool) InUse

func (bp *Pool) InUse() int

InUse returns the number of buffers in use which haven't been returned to the pool

func (*Pool) Put

func (bp *Pool) Put(buf []byte)

Put returns the buffer to the buffer cache or frees it

Note that if you try to return a buffer of the wrong size to Put it will panic.

Jump to

Keyboard shortcuts

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