recycle

package
v0.0.0-...-fbbe109 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2016 License: MIT Imports: 6 Imported by: 2

Documentation

Overview

Package recycle contains utilities for recyclable, concurrent read only memory usage.

Index

Constants

This section is empty.

Variables

View Source
var DefaultChunkSizes = func() (sz []int) {
	for chSz := minDefChunkSize; chSz <= maxDefChunkSize; chSz *= 2 {
		sz = append(sz, chSz)
	}
	return
}()

Functions

This section is empty.

Types

type Data

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

Data represents data which can have multiple concurrent readers and should been recycled in pool after Recycle call and when all concurrent reads are finished.

func (*Data) GoString

func (d *Data) GoString() string

func (*Data) NewReader

func (d *Data) NewReader() *DataReader

func (*Data) Recycle

func (d *Data) Recycle()

func (*Data) WriteTo

func (d *Data) WriteTo(w io.Writer) (nn int64, err error)

type DataReader

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

func (*DataReader) Close

func (r *DataReader) Close() error

func (*DataReader) Read

func (r *DataReader) Read(p []byte) (nn int, err error)

Read method is for test purpose only. WriteTo should be uses instead.

func (*DataReader) WriteTo

func (r *DataReader) WriteTo(w io.Writer) (nn int64, err error)

type LeakCallback

type LeakCallback func(*Data)
var PanicOnLeak LeakCallback = func(d *Data) {
	panic(fmt.Sprintf("recycle.Data leaked: %#v.", d))
}
var WarnOnLeak LeakCallback = func(d *Data) {
	println("WARN: recycle.Data leaked.")
}

func NotifyOnLeak

func NotifyOnLeak(leak chan<- *Data) LeakCallback

type Pool

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

func NewPool

func NewPool() *Pool

func NewPoolSizes

func NewPoolSizes(chunkSizes []int) *Pool

NewPoolSizes creates new pool, which produce chunks with sizes described in chunkSizes. chunkSizes should be sorted.

func (*Pool) MaxChunkSize

func (p *Pool) MaxChunkSize() int

func (*Pool) MinChunkSize

func (p *Pool) MinChunkSize() int

func (*Pool) ReadData

func (p *Pool) ReadData(r io.Reader, size int) (*Data, error)

func (*Pool) SetLeakCallback

func (p *Pool) SetLeakCallback(cb LeakCallback)

SetLeakCallback sets callback, which is called before GC of not recycled data. Note: this is for test and debug purpose only.

Jump to

Keyboard shortcuts

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