alloc

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Allocator

type Allocator[P Ptr[P]] interface {
	// Alloc allocates a new object and returns its pointer.
	Alloc() P

	// Free the ptr allocated by Alloc().
	Free(ptr P)

	// Reset retains underlaying storage of allocated objects but clears out
	// all existing data.
	Reset()
}

Allocator defines required methods for an allocator implementation.

type BumpAlloc

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

BumpAlloc manages the allocation of type T

func NewBumpAlloc

func NewBumpAlloc[T any]() *BumpAlloc[T]

func (*BumpAlloc[T]) Alloc

func (ba *BumpAlloc[T]) Alloc() RawPtr

func (*BumpAlloc[T]) Free

func (alloc *BumpAlloc[T]) Free(p RawPtr)

func (*BumpAlloc[T]) Reset

func (a *BumpAlloc[T]) Reset()

type NativeAlloc

type NativeAlloc[T any] struct{}

NativeAlloc allocates new objects with golang built-in new(T).

func NewNativeAlloc

func NewNativeAlloc[T any]() (alloc NativeAlloc[T])

func (NativeAlloc[T]) Alloc

func (NativeAlloc[T]) Alloc() UnsafePtr

func (NativeAlloc[T]) Free

func (NativeAlloc[T]) Free(p UnsafePtr)

func (NativeAlloc[T]) Reset

func (NativeAlloc[T]) Reset()

type PoolAlloc

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

func NewPoolAllocator

func NewPoolAllocator[T any](allocNew func() any) *PoolAlloc[T]

func (*PoolAlloc[T]) Alloc

func (a *PoolAlloc[T]) Alloc() UnsafePtr

func (*PoolAlloc[T]) Free

func (a *PoolAlloc[T]) Free(p UnsafePtr)

func (*PoolAlloc[T]) Reset

func (a *PoolAlloc[T]) Reset()

type Ptr

type Ptr[Self any] interface {
	// IsNull returns true when the pointer points to nowhere.
	//
	// Implementations MUST return true for zero value.
	IsNull() bool

	// Load returns an in-memory address as the handle of the pointed object.
	Load() unsafe.Pointer

	// Equals returns true if the two pointer points to the same target.
	Equals(other Self) bool
}

Ptr defines required methods for pointers.

type RawPtr

type RawPtr uintptr

RawPtr is a uintptr, ignored by GC

func (RawPtr) Equals

func (p RawPtr) Equals(o RawPtr) bool

func (RawPtr) IsNull

func (p RawPtr) IsNull() bool

func (RawPtr) Load

func (p RawPtr) Load() unsafe.Pointer

type SizedAlloc

type SizedAlloc uintptr

SizedAlloc is make([]byte, SizedAlloc).

NOTE: zero-size data types will use nil pointer.

func NewSizedAlloc

func NewSizedAlloc(size uintptr) SizedAlloc

func (SizedAlloc) Alloc

func (a SizedAlloc) Alloc() UnsafePtr

func (SizedAlloc) Free

func (SizedAlloc) Free(p UnsafePtr)

func (SizedAlloc) Reset

func (SizedAlloc) Reset()

type UnsafePtr

type UnsafePtr struct{ Addr unsafe.Pointer }

UnsafePtr is a unsafe.Pointer, it locks the referenced memeory address during GC.

func (UnsafePtr) Equals

func (p UnsafePtr) Equals(o UnsafePtr) bool

func (UnsafePtr) IsNull

func (p UnsafePtr) IsNull() bool

func (UnsafePtr) Load

func (p UnsafePtr) Load() unsafe.Pointer

Jump to

Keyboard shortcuts

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