alloc

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone[T any](alloc M, x T) T

func Make

func Make[E any](alloc M, len, cap int) []E

func MakeTyped

func MakeTyped(alloc M, et *abi.Type, len, cap int) unsafe.Pointer

func New

func New[T any](alloc M) *T

func SizeOutOfRange

func SizeOutOfRange(typSz uintptr, n int) (outOfRange bool)

func ZeroSized

func ZeroSized() unsafe.Pointer

Types

type A

type A interface {
	NewArena() Arena
}

A for arena creations.

type Arena

type Arena interface {
	M
	// Discard this arena, all allocated data will be gone.
	Discard()
}

Arena defines the arena interface.

type DenyNoneZero

type DenyNoneZero struct{}

DenyNoneZero implements M that only allows allocation of zero sized types.

func (DenyNoneZero) Free

func (DenyNoneZero) Free(typ *abi.Type, n uintptr, ptr unsafe.Pointer) Hint

func (DenyNoneZero) Malloc

func (DenyNoneZero) Malloc(typ *abi.Type, n uintptr, zeroize bool) unsafe.Pointer

func (DenyNoneZero) Palloc

func (DenyNoneZero) Palloc(size uintptr) unsafe.Pointer

type H

type H interface {
	M
	MallocHeap(typ *abi.Type, n uintptr, zerioze bool) unsafe.Pointer
}

H for heap allocations.

type Hint

type Hint uint32

Hint for freeing the allocated memory

TODO: TBD

func Free

func Free[T any](alloc M, x T) Hint

type M

type M interface {
	// Malloc allocates memory for n elements of typ.
	//
	// NOTE: for bytes allocations, typ may be nil.
	Malloc(typ *abi.Type, n uintptr, zeroize bool) unsafe.Pointer

	// Free memory allocated for n elements.
	//
	// NOTE: for freeing types without heap pointer, typ may be nil
	// and in that case, n is the bytes allocated.
	Free(typ *abi.Type, n uintptr, ptr unsafe.Pointer) Hint
}

M for general purpose allocations.

type P

type P interface {
	Palloc(size uintptr) unsafe.Pointer
}

P for persistant allocations.

type S

type S interface {
	NewStack(size uintptr) unsafe.Pointer
}

S for stack allocations.

Directories

Path Synopsis
Package sbrkalloc provides an allocator implementation using sbrk only.
Package sbrkalloc provides an allocator implementation using sbrk only.

Jump to

Keyboard shortcuts

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