autopool

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package autopool provides the ability to modify objects in a Pool so that they are automatically added back to the pool on GC. This allows submitting to the pool objects that leave your code's control, such as a protocol buffer that is gRPC will encode to the caller. It should be noted that this package has no control over when the GC frees the object (if ever), so you should explicitly call .Put() when you can. This will not stop GC by the sync.Pool itself.

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 provides a sync.Pool where GC'd objects are put back into the Pool automatically.

func New

func New(pool *sync.Pool) *Pool

New modifies the existing *sync.Pool to return objects that attempt to return to the Pool when the GC is prepared to free them. Only safe to use before the Pool is used.

func (*Pool) Get

func (p *Pool) Get() interface{}

Get works the same as sync.Pool.Get() with the exception that a finalizer is set on the object to return the item to the Pool when it is GC'd. Note: objects passed that depend on finalizers should not be used here, as they are cleared at certain points in the objects lifetime by this package.

func (*Pool) Put

func (p *Pool) Put(x interface{})

Put adds x to the pool.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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