pool

package
v0.31.9 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxBufferSize = 20000

MaxBufferSize is the maximum size that a buffer will be allowed to grow before it is automatically removed from the buffer pool. This prevents large memory allocations from permanently sitting in the buffer pool. You should set MaxBufferSize to a value that is bigger than most http request sizes.

Functions

func GetBuffer

func GetBuffer() *bytes.Buffer

GetBuffer returns a buffer from the pool. It will create a new pool if one is not already allocated. This allows you to inject your own replacement BufferPool before the first use of GetBuffer()

func PutBuffer

func PutBuffer(buffer *bytes.Buffer)

PutBuffer puts a buffer back into the pool. Be very careful that you do not refer to the buffer after putting it back, including using a slice of a buffer.

Types

type BufferPoolI

type BufferPoolI interface {
	GetBuffer() *bytes.Buffer
	PutBuffer(buffer *bytes.Buffer)
}

BufferPoolI describes a buffer pool that can be used to improve memory allocation and garbage collection for frequently used memory buffers.

var BufferPool BufferPoolI

BufferPool is the global buffer pool used by the page drawing system. You can use it to get buffers for you own writes as well. The default buffer pool uses MaxBufferSize to limit the size of buffers that are put back into the pool. If a particular http request required a large buffer to satisfy, this prevents that buffer from hanging around too long. You should set MaxBufferSize to a value that is bigger than most http request sizes.

Jump to

Keyboard shortcuts

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