bytepool

package module
v0.0.0-...-5e3a9ea Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2016 License: MIT Imports: 1 Imported by: 4

README

bytepool

Alloc temporary variable sized byte buffers from sync.Pools.

Example:

bs := bytepool.Alloc(134)
defer bytepool.Free(bs)
n,e := myfile.Read(bs)
bs = bs[0:n]

License: MIT

GoDoc

Test code coverage 100%

Documentation

Overview

Variable sized pools of bytes using sync.Pools underneath.

Index

Constants

View Source
const MaxSize = 1 << 23

MaxSize is the supported maximum size

Variables

This section is empty.

Functions

func Alloc

func Alloc(size int) []byte

Alloc a slice of bytes with the given size. Sizes till MaxSize are supported, for larger sizes nil will be returned. The slices are taken from sync.Pool caches sized to the nearest power of two and truncated to the size supplied. This function may be called concurrently.

func Free

func Free(bs []byte)

Free a byte slice allocated by Alloc. The argument may be shorted from the original allocation, it is reset to len = cap. This function may be called concurrently.

Types

This section is empty.

Jump to

Keyboard shortcuts

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