mempool

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

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 1 Imported by: 1

README

go-mempool

very simple memory pool implementation

Documentation

Index

Constants

View Source
const DefaultDirtyFactor = 128

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool[T any] struct {

	// New is an optionally provided
	// allocator used when no value
	// is available for use in pool.
	New func() T

	// Reset is an optionally provided
	// value resetting function called
	// on passed value to Put().
	Reset func(T)

	UnsafePool
}

Pool provides a type-safe form of UnsafePool using generics.

Note it is NOT safe for concurrent use, you must protect it yourself!

func (*Pool[T]) Get

func (p *Pool[T]) Get() T

func (*Pool[T]) Put

func (p *Pool[T]) Put(t T)

type UnsafePool

type UnsafePool struct {

	// DirtyFactor determines the max
	// number of $dirty count before
	// pool is garbage collected. Where:
	// $dirty = len(current) - len(victim)
	DirtyFactor int
	// contains filtered or unexported fields
}

UnsafePool provides an incredibly simple memory pool implementation that stores ptrs to memory values, and regularly flushes internal pool structures according to DirtyFactor.

Note it is NOT safe for concurrent use, you must protect it yourself!

func (*UnsafePool) Get

func (p *UnsafePool) Get() unsafe.Pointer

func (*UnsafePool) Put

func (p *UnsafePool) Put(ptr unsafe.Pointer)

Jump to

Keyboard shortcuts

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