mmm

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

README

MMM

Manual memory management for the Go Programming Language.

Package mmm provides functions and helpers to manually manage memory in Go programs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alloc

func Alloc[T any]() *T

Alloc returns a pointer to a newly allocated T. It does not zero the memory.

func Free

func Free[T any](v *T)

Free returns the memory for a pointer allocated by this package to the operating system.

func New

func New[T any]() *T

New returns a pointer to a newly allocated and zeroed T.

func WithCleanup

func WithCleanup[T any](d *ErrCleanup, p *T) *T

WithCleanup adds the pointer p to the list of pointers that might need cleanup on d and returns it.

Types

type ErrCleanup

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

ErrCleanup allows to free several pointers when an error occurs.

func Cleanup

func Cleanup(err *error) (*ErrCleanup, func())

Cleanup returns an initialised *ErrCleanup and the function that does the cleanup.

type Vec

type Vec[T any] struct {
	// contains filtered or unexported fields
}

Vec is a generic vector.

func NewVec

func NewVec[T any](elems ...T) *Vec[T]

func NewVecWithCap

func NewVecWithCap[T any](cap int) *Vec[T]

func VecMap

func VecMap[T, U any](from *Vec[T], fn func(T) U) *Vec[U]

func (*Vec[T]) Append

func (v *Vec[T]) Append(elems ...T)

Append items to the end of the vector, resizing if necessary.

func (*Vec[T]) Cap

func (v *Vec[T]) Cap() int

Cap returns the maximum possible lenght of the vector before needing to reallocate the underlying memory.

func (*Vec[T]) ExpandBy

func (v *Vec[T]) ExpandBy(n int)

ExpandBy increases the capacity of the vector such that it will be able to hold an extra s.Len()+n items.

func (*Vec[T]) Free

func (v *Vec[T]) Free()

Free frees the memory that the vector uses and the vector struct itself.

func (*Vec[T]) Get

func (v *Vec[T]) Get(i int) T

Get the element at index i.

func (*Vec[T]) GoSlice

func (v *Vec[T]) GoSlice() []T

GoSlice turns the Vec[T] into a Go slice whose memory is managed by the Go runtime.

func (*Vec[T]) Len

func (v *Vec[T]) Len() int

Len returns the number of items currently in the vector.

func (*Vec[T]) Push

func (v *Vec[T]) Push(elem T)

Push an element to the end of the vector, resizing if necessary.

func (*Vec[T]) Resize

func (v *Vec[T]) Resize(capcity int)

Resize sets the capacity of the vector. It can truncate the contents if capacity is less than Len().

func (*Vec[T]) Set

func (v *Vec[T]) Set(i int, elem T)

Set the element at index i to elem.

func (*Vec[T]) Slice

func (v *Vec[T]) Slice() []T

Slice returns the Vec[T] into []T. Calling append with this slice is undefined behaviour. Useful to iterate over the vector with range.

Directories

Path Synopsis
internal
c
Package c wraps CGO calls so that gopls doesn't complain too much.
Package c wraps CGO calls so that gopls doesn't complain too much.

Jump to

Keyboard shortcuts

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