memory

package module
v0.0.0-...-db5bb35 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2012 License: BSD-2-Clause Imports: 2 Imported by: 2

README

Simple memory manager. Useful in some cases where managing your own memory is simple, and where waiting for the GC to collect it and make it reusable causes unnecessary slowdown.

manager := memory.NewManager()

// Grab a block of a particular size
block := manager.GetBlock(2000)

// Give the block back to the manager so we can use it again later.
manager.FreeBlock(block)

Documentation

Overview

In cases where Go's garbage collecter is unresponsive, or even broken, this allows you to easily manage blocks of memory. This can be useful if you anticipate churning through lots of memory very quickly. This package creates a default Manager that can be used through the package functions, but you can create your own Manager if you want to eventually return the memory back to Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FreeBlock

func FreeBlock(b []byte)

Returns a block back to the Manager so that it can be reused. Panics if this block has already been freed, or if it was not allocated by this manager.

func GetBlock

func GetBlock(n int) []byte

Returns a slice of length n of the smallest block available that is at least that large. Will reuse an existing block if possible, otherwise it will allocate a new one.

func TotalAllocations

func TotalAllocations() string

Human-readable rundown on how many blocks have been reserved by this manager, and which ones are currently in use.

Types

type Manager

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

A Manager allocates memory as necessary and won't free it as long as it exists. If you call GetBlock() then it should be followed by a FreeBlock() when you are done with it.

func NewManager

func NewManager() *Manager

func (*Manager) FreeBlock

func (m *Manager) FreeBlock(b []byte)

Returns a block back to the Manager so that it can be reused. Panics if this block has already been freed, or if it was not allocated by this manager.

func (*Manager) GetBlock

func (m *Manager) GetBlock(n int) []byte

Returns a slice of length n of the smallest block available that is at least that large. Will reuse an existing block if possible, otherwise it will allocate a new one.

func (*Manager) TotalAllocations

func (m *Manager) TotalAllocations() string

Human-readable rundown on how many blocks have been reserved by this manager, and which ones are currently in use.

Jump to

Keyboard shortcuts

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