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 ¶
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 ¶
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 ¶
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 ¶
Human-readable rundown on how many blocks have been reserved by this manager, and which ones are currently in use.