rclone: github.com/ncw/rclone/lib/pool Index | Files

package pool

import "github.com/ncw/rclone/lib/pool"

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


Package Files


type Pool Uses

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 Uses

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 Uses

func (bp *Pool) Alloced() int

Alloced returns the number of buffers allocated and not yet freed

func (*Pool) Flush Uses

func (bp *Pool) Flush()

Flush the entire buffer pool

func (*Pool) Get Uses

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

Get a buffer from the pool or allocate one

func (*Pool) InPool Uses

func (bp *Pool) InPool() int

InPool returns the number of buffers in the pool

func (*Pool) InUse Uses

func (bp *Pool) InUse() int

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

func (*Pool) Put Uses

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.

Package pool imports 5 packages (graph). Updated 2019-08-13. Refresh now. Tools for package owners.