nogc

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: MIT Imports: 8 Imported by: 3

README

Go without Garbage Collection

High performance manual memory management for Go and TinyGo. The goal is to narrow the gap between Go and C/C++/Rust for low latency / high main-memory use cases. If you don't know why you would need this, then you probably don't. Programming around Go's GC is more difficult in a general sense.

Allocators

rpmalloc - Go

Rampant Pixel allocator. Extremely performant multi-threaded allocator that has the best overall performance of any major general purpose allocator. Destroys JEMalloc and TCMalloc in benchmarks at the cost of a little more memory use. Edges out mimalloc after 1 thread. The standard libc "malloc, free" are overridden with rpmalloc alternatives so any other C/C++/Rust code will automatically use rpmalloc. In order to have Go scheduler managed pthreads cleanup there thread local allocations, need to preload the (librpmalloc.so/dylib).

TLSF - TinyGo (default) / Go (rpmalloc is default)

Two-Level Segregated Fit real-time allocator. Ported from AssemblyScript's TypeScript implementation in pure Go. Simple compact constant time allocator for predictable real-time performance. Intended for TinyGo WASM, but works on other TinyGo platforms as well as Go.

unsafe CGO

libfuzzerCall in Go runtime for amd64 and arm64 architectures is utilized to dramatically reduce CGO cost by 1,000%+. On a 2019 MacBook Pro the overhead is reduced from 53.9ns to 2.9ns or (3.9ns via linked runtime.libfuzzerCall). ~2ns on a 2021 MacBook Pro M1. Do not blindly replace normal CGO calls with unsafe CGO calls. The Go scheduler is tricky with threads and unsafe CGO calls must be non-blocking or guarantee thread blocking (generally a bad idea). Rule of thumb is guaranteed CPU bound functions.

Collections

Building on top of highly capable allocators and low unsafe CGO costs, external high-performance C/C++ libraries are integrated. The goal is to build a high-quality collection of extremely performant native collections that utilize the system allocator.

  • Read/Write SpinLock fair and unfair (C++ via Meta's/Facebook's Folly project)
  • ART (Adaptive Radix Tree) (C via modified version of libart) this is also a great Go map alternative
  • BTree (C via tidwall's btree.c lib) use for heavy range operation usage
  • LockFree Queue (Go)
  • Cache w/ eviction strategies (TODO)

These collections incur Zero GC cost. A highly optimized C++ Read/Write Spin Lock is embedded to allow concurrency control across Go / C boundaries if needed. It utilizes unsafe CGO and may block a Go scheduler thread under heavy write contention.

Net

Use Go based net libs like gnet, evio, fasthttp, etc. If using evio or something similar, allocate memory using the nogc allocator. For high connection counts, pool goroutines.

Object Models

One obvious issue with manual memory management is standard go structs with pointers cannot be supported directly (strings, []byte, *struct{}, map, chan, etc).

Check out our other open source project: https://github.com/moontrade/proto

It's a new wire format similar to protocol buffers and flatbuffers. Layout is flat like flatbuffers. Code generation allows for rich Go APIs which are backed by manual or gc allocated memory.

Why not just use C/C++/Rust?

All of those languages are great. This project uses C/C++ extensively and carefully. C/C++/Rust are great for extremely performance sensitive parts. Go is extremely productive while also compiling to native (smallish) binaries. We find Go much better for prototyping ideas. The only major hurdle we have encountered is the GC. One weakness is storing billion(s) of allocations in a map for example. Go's GC needs to scan an object graph continuously. We build low-latency software. Hopping over to a Redis server just for access to JEMalloc is a waste of time. Instead, that can just be embedded and with a better general purpose allocator like rpmalloc. Go also has good Raft implementations if high-availability is needed.

Documentation

Index

Constants

View Source
const PtrSize = 4 << (^uintptr(0) >> 63)

PtrSize is the size of a pointer in bytes - unsafe.Sizeof(uintptr(0)) but as an ideal constant. It is also the size of the machine's native word size (that is, 4 on 32-bit systems, 8 on 64-bit).

Variables

View Source
var (
	ErrOutOfMemory = errors.New("out of memory")
)

Functions

func Cmp

func Cmp(a, b string) int

func Compare

func Compare(a, b unsafe.Pointer, n uintptr) int

func Copy

func Copy(dst, src unsafe.Pointer, n uintptr)

func Equals

func Equals(a, b unsafe.Pointer, size uintptr) bool

func Fastrand

func Fastrand() uint32

func FloorToPowerOfTwo

func FloorToPowerOfTwo(n int) int

FloorToPowerOfTwo returns the greatest power of two integer value less than or equal to n.

func Free

func Free(p Pointer)

Free calls Free on the system allocator

func Init

func Init()

func IsPowerOfTwo

func IsPowerOfTwo(n int) bool

IsPowerOfTwo reports whether given integer is a power of two.

func LogarithmicRange

func LogarithmicRange(min, max int, cb func(int))

LogarithmicRange iterates from ceiled to power of two min to max, calling cb on each iteration.

func Move

func Move(to, from unsafe.Pointer, n uintptr)

Move copies n bytes from "from" to "to".

Move ensures that any pointer in "from" is written to "to" with an indivisible write, so that racy reads cannot observe a half-written pointer. This is necessary to prevent the garbage collector from observing invalid pointers, and differs from Memmove in unmanaged languages. However, Memmove is only required to do this if "from" and "to" may contain pointers, which can only be the case if "from", "to", and "n" are all be word-aligned.

Implementations are in memmove_*.s.

func PrintGCStats added in v0.1.5

func PrintGCStats()

func Scope

func Scope(fn func(a AutoFree))

func Sizeof added in v0.1.5

func Sizeof(ptr Pointer) uintptr

func Zero

func Zero(ptr unsafe.Pointer, n uintptr)

Zero clears n bytes starting at ptr.

Usually you should use typedmemclr. memclrNoHeapPointers should be used only when the caller knows that *ptr contains no heap pointers because either:

*ptr is initialized memory and its type is pointer-free, or

*ptr is uninitialized memory (e.g., memory that's being reused for a new allocation) and hence contains only "junk".

memclrNoHeapPointers ensures that if ptr is pointer-aligned, and n is a multiple of the pointer size, then any pointer-aligned, pointer-sized portion is cleared atomically. Despite the function name, this is necessary because this function is the underlying implementation of typedmemclr and memclrHasPointers. See the doc of Memmove for more details.

The (CPU-specific) implementations of this function are in memclr_*.s.

Types

type AutoFree

type AutoFree uintptr

AutoFree is a singly linked list (Stack) of nodes which contain pointers that will all free when Free is called. uintptr is used to ensure the compiler doesn't confuse it for a Go GC managed pointer.

func NewAuto

func NewAuto(nodeSize uintptr) AutoFree

func (AutoFree) Alloc

func (af AutoFree) Alloc(size uintptr) Pointer

func (AutoFree) AllocCap

func (af AutoFree) AllocCap(size uintptr) FatPointer

func (AutoFree) Bytes

func (af AutoFree) Bytes(size uintptr) Bytes

func (*AutoFree) Close

func (af *AutoFree) Close() error

Close releases / frees every allocation

func (AutoFree) Count

func (af AutoFree) Count() uintptr

func (*AutoFree) Free

func (af *AutoFree) Free()

Free releases every allocation

func (*AutoFree) HasNext

func (af *AutoFree) HasNext() bool

func (AutoFree) Max

func (af AutoFree) Max() uintptr

func (*AutoFree) Next

func (af *AutoFree) Next() AutoFree

func (*AutoFree) Print

func (af *AutoFree) Print()

func (*AutoFree) Scope

func (af *AutoFree) Scope(fn func(AutoFree))

func (AutoFree) Size

func (af AutoFree) Size() uintptr

type Bytes

type Bytes struct {
	Pointer // Use for unchecked unsafe access
}

Bytes is a compact single dynamic allocation to be used as an unsafe replacement for string.

func AllocBytes

func AllocBytes(size uintptr) Bytes

func BytesOf added in v0.1.4

func BytesOf(b []byte) Bytes

func BytesOfString added in v0.1.4

func BytesOfString(s string) Bytes

func BytesRef

func BytesRef(ptr Pointer) *Bytes

func (*Bytes) Append

func (s *Bytes) Append(value Bytes)

func (*Bytes) AppendByte

func (s *Bytes) AppendByte(value byte)

func (*Bytes) AppendByteString added in v0.1.2

func (s *Bytes) AppendByteString(value byte)

func (*Bytes) AppendBytes

func (s *Bytes) AppendBytes(value []byte)

func (*Bytes) AppendFloat32

func (s *Bytes) AppendFloat32(value float32)

func (*Bytes) AppendFloat32BE

func (s *Bytes) AppendFloat32BE(value float32)

func (*Bytes) AppendFloat32LE

func (s *Bytes) AppendFloat32LE(value float32)

func (*Bytes) AppendFloat32String added in v0.1.3

func (s *Bytes) AppendFloat32String(value float32)

func (*Bytes) AppendFloat64

func (s *Bytes) AppendFloat64(value float64)

func (*Bytes) AppendFloat64BE

func (s *Bytes) AppendFloat64BE(value float64)

func (*Bytes) AppendFloat64LE

func (s *Bytes) AppendFloat64LE(value float64)

func (*Bytes) AppendFloat64String added in v0.1.3

func (s *Bytes) AppendFloat64String(value float64)

func (*Bytes) AppendInt

func (s *Bytes) AppendInt(value int)

func (*Bytes) AppendInt16

func (s *Bytes) AppendInt16(value int16)

func (*Bytes) AppendInt16BE

func (s *Bytes) AppendInt16BE(value int16)

func (*Bytes) AppendInt16LE

func (s *Bytes) AppendInt16LE(value int16)

func (*Bytes) AppendInt16String added in v0.1.2

func (s *Bytes) AppendInt16String(value int16)

func (*Bytes) AppendInt24

func (s *Bytes) AppendInt24(value int32)

func (*Bytes) AppendInt24BE

func (s *Bytes) AppendInt24BE(value int32)

func (*Bytes) AppendInt24LE

func (s *Bytes) AppendInt24LE(value int32)

func (*Bytes) AppendInt32

func (s *Bytes) AppendInt32(value int32)

func (*Bytes) AppendInt32BE

func (s *Bytes) AppendInt32BE(value int32)

func (*Bytes) AppendInt32LE

func (s *Bytes) AppendInt32LE(value int32)

func (*Bytes) AppendInt32String added in v0.1.2

func (s *Bytes) AppendInt32String(value int32)

func (*Bytes) AppendInt40

func (s *Bytes) AppendInt40(value int64)

func (*Bytes) AppendInt40BE

func (s *Bytes) AppendInt40BE(value int64)

func (*Bytes) AppendInt40LE

func (s *Bytes) AppendInt40LE(value int64)

func (*Bytes) AppendInt48

func (s *Bytes) AppendInt48(value int64)

func (*Bytes) AppendInt48BE

func (s *Bytes) AppendInt48BE(value int64)

func (*Bytes) AppendInt48LE

func (s *Bytes) AppendInt48LE(value int64)

func (*Bytes) AppendInt56

func (s *Bytes) AppendInt56(value int64)

func (*Bytes) AppendInt56BE

func (s *Bytes) AppendInt56BE(value int64)

func (*Bytes) AppendInt56LE

func (s *Bytes) AppendInt56LE(value int64)

func (*Bytes) AppendInt64

func (s *Bytes) AppendInt64(value int64)

func (*Bytes) AppendInt64BE

func (s *Bytes) AppendInt64BE(value int64)

func (*Bytes) AppendInt64LE

func (s *Bytes) AppendInt64LE(value int64)

func (*Bytes) AppendInt64String added in v0.1.2

func (s *Bytes) AppendInt64String(value int64)

func (*Bytes) AppendInt8

func (s *Bytes) AppendInt8(value int8)

func (*Bytes) AppendInt8String added in v0.1.2

func (s *Bytes) AppendInt8String(value int8)

func (*Bytes) AppendIntString added in v0.1.2

func (s *Bytes) AppendIntString(value int)

func (*Bytes) AppendPointer

func (s *Bytes) AppendPointer(value Pointer)

func (*Bytes) AppendString

func (s *Bytes) AppendString(value string)

func (*Bytes) AppendUint added in v0.1.6

func (s *Bytes) AppendUint(value uint)

func (*Bytes) AppendUint16 added in v0.1.6

func (s *Bytes) AppendUint16(value uint16)

func (*Bytes) AppendUint16BE added in v0.1.6

func (s *Bytes) AppendUint16BE(value uint16)

func (*Bytes) AppendUint16LE added in v0.1.6

func (s *Bytes) AppendUint16LE(value uint16)

func (*Bytes) AppendUint16String added in v0.1.6

func (s *Bytes) AppendUint16String(value uint16)

func (*Bytes) AppendUint24 added in v0.1.6

func (s *Bytes) AppendUint24(value uint32)

func (*Bytes) AppendUint24BE added in v0.1.6

func (s *Bytes) AppendUint24BE(value uint32)

func (*Bytes) AppendUint24LE added in v0.1.6

func (s *Bytes) AppendUint24LE(value uint32)

func (*Bytes) AppendUint32 added in v0.1.6

func (s *Bytes) AppendUint32(value uint32)

func (*Bytes) AppendUint32BE added in v0.1.6

func (s *Bytes) AppendUint32BE(value uint32)

func (*Bytes) AppendUint32LE added in v0.1.6

func (s *Bytes) AppendUint32LE(value uint32)

func (*Bytes) AppendUint32String added in v0.1.6

func (s *Bytes) AppendUint32String(value uint32)

func (*Bytes) AppendUint40 added in v0.1.6

func (s *Bytes) AppendUint40(value uint64)

func (*Bytes) AppendUint40BE added in v0.1.6

func (s *Bytes) AppendUint40BE(value uint64)

func (*Bytes) AppendUint40LE added in v0.1.6

func (s *Bytes) AppendUint40LE(value uint64)

func (*Bytes) AppendUint48 added in v0.1.6

func (s *Bytes) AppendUint48(value uint64)

func (*Bytes) AppendUint48BE added in v0.1.6

func (s *Bytes) AppendUint48BE(value uint64)

func (*Bytes) AppendUint48LE added in v0.1.6

func (s *Bytes) AppendUint48LE(value uint64)

func (*Bytes) AppendUint56 added in v0.1.6

func (s *Bytes) AppendUint56(value uint64)

func (*Bytes) AppendUint56BE added in v0.1.6

func (s *Bytes) AppendUint56BE(value uint64)

func (*Bytes) AppendUint56LE added in v0.1.6

func (s *Bytes) AppendUint56LE(value uint64)

func (*Bytes) AppendUint64 added in v0.1.6

func (s *Bytes) AppendUint64(value uint64)

func (*Bytes) AppendUint64BE added in v0.1.6

func (s *Bytes) AppendUint64BE(value uint64)

func (*Bytes) AppendUint64LE added in v0.1.6

func (s *Bytes) AppendUint64LE(value uint64)

func (*Bytes) AppendUint64String added in v0.1.6

func (s *Bytes) AppendUint64String(value uint64)

func (*Bytes) AppendUint8 added in v0.1.6

func (s *Bytes) AppendUint8(value uint8)

func (*Bytes) AppendUint8String added in v0.1.6

func (s *Bytes) AppendUint8String(value uint8)

func (*Bytes) AppendUintString added in v0.1.6

func (s *Bytes) AppendUintString(value uint)

func (*Bytes) AppendUintptr

func (s *Bytes) AppendUintptr(value uintptr)

func (*Bytes) Byte

func (s *Bytes) Byte(offset int) byte

func (*Bytes) Bytes

func (s *Bytes) Bytes() []byte

func (*Bytes) CString

func (s *Bytes) CString() unsafe.Pointer

func (Bytes) Cap

func (b Bytes) Cap() int

func (*Bytes) CheckBounds

func (s *Bytes) CheckBounds(offset int) bool

func (*Bytes) Clone

func (s *Bytes) Clone() Bytes

Clone creates a copy of this instance of Bytes

func (*Bytes) EnsureCap

func (s *Bytes) EnsureCap(neededCap int)

EnsureCap ensures the capacity is at least neededCap in size

func (*Bytes) EnsureLen

func (s *Bytes) EnsureLen(neededLen int)

EnsureLen ensures the length is at least neededLen in size If not, EnsureCap(neededLen) is called and the length set to neededLen.

func (*Bytes) Equals

func (s *Bytes) Equals(o Bytes) bool

func (*Bytes) Float32

func (s *Bytes) Float32(offset int) float32

func (*Bytes) Float32BE

func (s *Bytes) Float32BE(offset int) float32

func (*Bytes) Float32LE

func (s *Bytes) Float32LE(offset int) float32

func (*Bytes) Float64

func (s *Bytes) Float64(offset int) float64

func (*Bytes) Float64BE

func (s *Bytes) Float64BE(offset int) float64

func (*Bytes) Float64LE

func (s *Bytes) Float64LE(offset int) float64

func (*Bytes) Free

func (s *Bytes) Free()

func (*Bytes) Hash32

func (s *Bytes) Hash32() uint32

func (*Bytes) Hash64

func (s *Bytes) Hash64() uint64

func (*Bytes) Int

func (s *Bytes) Int(offset int) int

func (*Bytes) Int16

func (s *Bytes) Int16(offset int) int16

func (*Bytes) Int16BE

func (s *Bytes) Int16BE(offset int) int16

func (*Bytes) Int16LE

func (s *Bytes) Int16LE(offset int) int16

func (*Bytes) Int24

func (s *Bytes) Int24(offset int) int32

func (*Bytes) Int24BE

func (s *Bytes) Int24BE(offset int) int32

func (*Bytes) Int24LE

func (s *Bytes) Int24LE(offset int) int32

func (*Bytes) Int32

func (s *Bytes) Int32(offset int) int32

func (*Bytes) Int32BE

func (s *Bytes) Int32BE(offset int) int32

func (*Bytes) Int32LE

func (s *Bytes) Int32LE(offset int) int32

func (*Bytes) Int40

func (s *Bytes) Int40(offset int) int64

func (*Bytes) Int40BE

func (s *Bytes) Int40BE(offset int) int64

func (*Bytes) Int40LE

func (s *Bytes) Int40LE(offset int) int64

func (*Bytes) Int48

func (s *Bytes) Int48(offset int) int64

func (*Bytes) Int48BE

func (s *Bytes) Int48BE(offset int) int64

func (*Bytes) Int48LE

func (s *Bytes) Int48LE(offset int) int64

func (*Bytes) Int56

func (s *Bytes) Int56(offset int) int64

func (*Bytes) Int56BE

func (s *Bytes) Int56BE(offset int) int64

func (*Bytes) Int56LE

func (s *Bytes) Int56LE(offset int) int64

func (*Bytes) Int64

func (s *Bytes) Int64(offset int) int64

func (*Bytes) Int64BE

func (s *Bytes) Int64BE(offset int) int64

func (*Bytes) Int64LE

func (s *Bytes) Int64LE(offset int) int64

func (*Bytes) Int8

func (s *Bytes) Int8(offset int) int8

func (Bytes) IsEmpty

func (s Bytes) IsEmpty() bool

func (*Bytes) IsNil

func (s *Bytes) IsNil() bool

func (Bytes) Len

func (b Bytes) Len() int

func (*Bytes) Metro64

func (s *Bytes) Metro64(seed uint64, offset, length int) uint64

func (*Bytes) PointerAt

func (s *Bytes) PointerAt(offset int) Pointer

func (*Bytes) Reset

func (s *Bytes) Reset()

Reset zeroes out the entire allocation and sets the length back to 0

func (*Bytes) Set

func (s *Bytes) Set(offset int, value Bytes)

func (*Bytes) SetByte

func (s *Bytes) SetByte(offset int, value byte)

func (*Bytes) SetBytes

func (s *Bytes) SetBytes(offset int, value []byte)

func (*Bytes) SetFloat32

func (s *Bytes) SetFloat32(offset int, value float32)

func (*Bytes) SetFloat32BE

func (s *Bytes) SetFloat32BE(offset int, value float32)

func (*Bytes) SetFloat32LE

func (s *Bytes) SetFloat32LE(offset int, value float32)

func (*Bytes) SetFloat64

func (s *Bytes) SetFloat64(offset int, value float64)

func (*Bytes) SetFloat64BE

func (s *Bytes) SetFloat64BE(offset int, value float64)

func (*Bytes) SetFloat64LE

func (s *Bytes) SetFloat64LE(offset int, value float64)

func (*Bytes) SetInt

func (s *Bytes) SetInt(offset int, value int)

func (*Bytes) SetInt16

func (s *Bytes) SetInt16(offset int, value int16)

func (*Bytes) SetInt16BE

func (s *Bytes) SetInt16BE(offset int, value int16)

func (*Bytes) SetInt16LE

func (s *Bytes) SetInt16LE(offset int, value int16)

func (*Bytes) SetInt24

func (s *Bytes) SetInt24(offset int, value int32)

func (*Bytes) SetInt24BE

func (s *Bytes) SetInt24BE(offset int, value int32)

func (*Bytes) SetInt24LE

func (s *Bytes) SetInt24LE(offset int, value int32)

func (*Bytes) SetInt32

func (s *Bytes) SetInt32(offset int, value int32)

func (*Bytes) SetInt32BE

func (s *Bytes) SetInt32BE(offset int, value int32)

func (*Bytes) SetInt32LE

func (s *Bytes) SetInt32LE(offset int, value int32)

func (*Bytes) SetInt40

func (s *Bytes) SetInt40(offset int, value int64)

func (*Bytes) SetInt40BE

func (s *Bytes) SetInt40BE(offset int, value int64)

func (*Bytes) SetInt40LE

func (s *Bytes) SetInt40LE(offset int, value int64)

func (*Bytes) SetInt48

func (s *Bytes) SetInt48(offset int, value int64)

func (*Bytes) SetInt48BE

func (s *Bytes) SetInt48BE(offset int, value int64)

func (*Bytes) SetInt48LE

func (s *Bytes) SetInt48LE(offset int, value int64)

func (*Bytes) SetInt56

func (s *Bytes) SetInt56(offset int, value int64)

func (*Bytes) SetInt56BE

func (s *Bytes) SetInt56BE(offset int, value int64)

func (*Bytes) SetInt56LE

func (s *Bytes) SetInt56LE(offset int, value int64)

func (*Bytes) SetInt64

func (s *Bytes) SetInt64(offset int, value int64)

func (*Bytes) SetInt64BE

func (s *Bytes) SetInt64BE(offset int, value int64)

func (*Bytes) SetInt64LE

func (s *Bytes) SetInt64LE(offset int, value int64)

func (*Bytes) SetInt8

func (s *Bytes) SetInt8(offset int, value int8)

func (*Bytes) SetLength

func (s *Bytes) SetLength(length int)

func (*Bytes) SetPointer

func (s *Bytes) SetPointer(offset int, value Pointer)

func (*Bytes) SetString

func (s *Bytes) SetString(offset int, value string)

func (*Bytes) SetUint added in v0.1.6

func (s *Bytes) SetUint(offset int, value uint)

func (*Bytes) SetUint16 added in v0.1.6

func (s *Bytes) SetUint16(offset int, value uint16)

func (*Bytes) SetUint16BE added in v0.1.6

func (s *Bytes) SetUint16BE(offset int, value uint16)

func (*Bytes) SetUint16LE added in v0.1.6

func (s *Bytes) SetUint16LE(offset int, value uint16)

func (*Bytes) SetUint24 added in v0.1.6

func (s *Bytes) SetUint24(offset int, value uint32)

func (*Bytes) SetUint24BE added in v0.1.6

func (s *Bytes) SetUint24BE(offset int, value uint32)

func (*Bytes) SetUint24LE added in v0.1.6

func (s *Bytes) SetUint24LE(offset int, value uint32)

func (*Bytes) SetUint32 added in v0.1.6

func (s *Bytes) SetUint32(offset int, value uint32)

func (*Bytes) SetUint32BE added in v0.1.6

func (s *Bytes) SetUint32BE(offset int, value uint32)

func (*Bytes) SetUint32LE added in v0.1.6

func (s *Bytes) SetUint32LE(offset int, value uint32)

func (*Bytes) SetUint40 added in v0.1.6

func (s *Bytes) SetUint40(offset int, value uint64)

func (*Bytes) SetUint40BE added in v0.1.6

func (s *Bytes) SetUint40BE(offset int, value uint64)

func (*Bytes) SetUint40LE added in v0.1.6

func (s *Bytes) SetUint40LE(offset int, value uint64)

func (*Bytes) SetUint48 added in v0.1.6

func (s *Bytes) SetUint48(offset int, value uint64)

func (*Bytes) SetUint48BE added in v0.1.6

func (s *Bytes) SetUint48BE(offset int, value uint64)

func (*Bytes) SetUint48LE added in v0.1.6

func (s *Bytes) SetUint48LE(offset int, value uint64)

func (*Bytes) SetUint56 added in v0.1.6

func (s *Bytes) SetUint56(offset int, value uint64)

func (*Bytes) SetUint56BE added in v0.1.6

func (s *Bytes) SetUint56BE(offset int, value uint64)

func (*Bytes) SetUint56LE added in v0.1.6

func (s *Bytes) SetUint56LE(offset int, value uint64)

func (*Bytes) SetUint64 added in v0.1.6

func (s *Bytes) SetUint64(offset int, value uint64)

func (*Bytes) SetUint64BE added in v0.1.6

func (s *Bytes) SetUint64BE(offset int, value uint64)

func (*Bytes) SetUint64LE added in v0.1.6

func (s *Bytes) SetUint64LE(offset int, value uint64)

func (*Bytes) SetUint8 added in v0.1.6

func (s *Bytes) SetUint8(offset int, value uint8)

SetUint8 is safe version. Will grow allocation if needed.

func (*Bytes) SetUintptr

func (s *Bytes) SetUintptr(offset int, value uintptr)

func (*Bytes) String

func (s *Bytes) String() string

func (*Bytes) Uint added in v0.1.6

func (s *Bytes) Uint(offset int) int

func (*Bytes) Uint16 added in v0.1.6

func (s *Bytes) Uint16(offset int) uint16

func (*Bytes) Uint16BE added in v0.1.6

func (s *Bytes) Uint16BE(offset int) uint16

func (*Bytes) Uint16LE added in v0.1.6

func (s *Bytes) Uint16LE(offset int) uint16

func (*Bytes) Uint24 added in v0.1.6

func (s *Bytes) Uint24(offset int) uint32

func (*Bytes) Uint24BE added in v0.1.6

func (s *Bytes) Uint24BE(offset int) uint32

func (*Bytes) Uint24LE added in v0.1.6

func (s *Bytes) Uint24LE(offset int) uint32

func (*Bytes) Uint32 added in v0.1.6

func (s *Bytes) Uint32(offset int) uint32

func (*Bytes) Uint32BE added in v0.1.6

func (s *Bytes) Uint32BE(offset int) uint32

func (*Bytes) Uint32LE added in v0.1.6

func (s *Bytes) Uint32LE(offset int) uint32

func (*Bytes) Uint40 added in v0.1.6

func (s *Bytes) Uint40(offset int) uint64

func (*Bytes) Uint40BE added in v0.1.6

func (s *Bytes) Uint40BE(offset int) uint64

func (*Bytes) Uint40LE added in v0.1.6

func (s *Bytes) Uint40LE(offset int) uint64

func (*Bytes) Uint48 added in v0.1.6

func (s *Bytes) Uint48(offset int) uint64

func (*Bytes) Uint48BE added in v0.1.6

func (s *Bytes) Uint48BE(offset int) uint64

func (*Bytes) Uint48LE added in v0.1.6

func (s *Bytes) Uint48LE(offset int) uint64

func (*Bytes) Uint56 added in v0.1.6

func (s *Bytes) Uint56(offset int) uint64

func (*Bytes) Uint56BE added in v0.1.6

func (s *Bytes) Uint56BE(offset int) uint64

func (*Bytes) Uint56LE added in v0.1.6

func (s *Bytes) Uint56LE(offset int) uint64

func (*Bytes) Uint64 added in v0.1.6

func (s *Bytes) Uint64(offset int) uint64

func (*Bytes) Uint64BE added in v0.1.6

func (s *Bytes) Uint64BE(offset int) uint64

func (*Bytes) Uint64LE added in v0.1.6

func (s *Bytes) Uint64LE(offset int) uint64

func (*Bytes) Uint8 added in v0.1.6

func (s *Bytes) Uint8(offset int) uint8

func (*Bytes) Uintptr

func (s *Bytes) Uintptr(offset int) uintptr

func (*Bytes) WyHash64

func (s *Bytes) WyHash64(seed uint64, offset, length int) uint64

func (Bytes) Zero

func (s Bytes) Zero()

Zero zeroes out the entire allocation.

type FatPointer

type FatPointer struct {
	Pointer
	// contains filtered or unexported fields
}

func FatPointerOf

func FatPointerOf(p Pointer, length uintptr) FatPointer

func FatPointerOfBool added in v0.1.4

func FatPointerOfBool(v *bool) FatPointer

func FatPointerOfBytes added in v0.1.4

func FatPointerOfBytes(v []byte) FatPointer

func FatPointerOfBytesRef added in v0.1.4

func FatPointerOfBytesRef(v *[]byte) FatPointer

func FatPointerOfFloat32 added in v0.1.4

func FatPointerOfFloat32(v *float32) FatPointer

func FatPointerOfFloat64 added in v0.1.4

func FatPointerOfFloat64(v *float64) FatPointer

func FatPointerOfInt16 added in v0.1.4

func FatPointerOfInt16(v *int16) FatPointer

func FatPointerOfInt32 added in v0.1.4

func FatPointerOfInt32(v *int32) FatPointer

func FatPointerOfInt64 added in v0.1.4

func FatPointerOfInt64(v *int64) FatPointer

func FatPointerOfInt8 added in v0.1.4

func FatPointerOfInt8(v *int8) FatPointer

func FatPointerOfString added in v0.1.4

func FatPointerOfString(s string) FatPointer

func FatPointerOfStringRef added in v0.1.4

func FatPointerOfStringRef(s *string) FatPointer

func FatPointerOfUInt16 added in v0.1.4

func FatPointerOfUInt16(v *uint16) FatPointer

func FatPointerOfUInt32 added in v0.1.4

func FatPointerOfUInt32(v *uint32) FatPointer

func FatPointerOfUInt64 added in v0.1.4

func FatPointerOfUInt64(v *uint64) FatPointer

func FatPointerOfUInt8 added in v0.1.4

func FatPointerOfUInt8(v *uint8) FatPointer

func (FatPointer) Bytes

func (fp FatPointer) Bytes() []byte

func (FatPointer) Clone

func (fp FatPointer) Clone() FatPointer

func (FatPointer) CloneAsBytes

func (fp FatPointer) CloneAsBytes() Bytes

func (*FatPointer) Len

func (fp *FatPointer) Len() uintptr

func (FatPointer) String

func (fp FatPointer) String() string

type HeapStats

type HeapStats struct {
	HeapSize        int64
	AllocSize       int64
	PeakAllocSize   int64
	FreeSize        int64
	Allocs          int32
	InitialPages    int32
	ConsecutiveLow  int32
	ConsecutiveHigh int32
	Pages           int32
	Grows           int32
	// contains filtered or unexported fields
}

HeapStats provides the metrics of an Allocator

func (*HeapStats) Fragmentation

func (s *HeapStats) Fragmentation() float32

type Pointer

type Pointer uintptr

Pointer is a wrapper around a raw pointer that is not unsafe.Pointer so Go won't confuse it for a potential GC managed pointer.

func Alloc

func Alloc(size uintptr) Pointer

Alloc calls Alloc on the system allocator

func AllocCap

func AllocCap(size uintptr) (Pointer, uintptr)

func AllocZeroed

func AllocZeroed(size uintptr) Pointer

func AllocZeroedCap

func AllocZeroedCap(size uintptr) (Pointer, uintptr)

func Calloc

func Calloc(num, size uintptr) Pointer

Alloc calls Alloc on the system allocator

func CallocCap

func CallocCap(num, size uintptr) (Pointer, uintptr)

func PointerOfString added in v0.1.4

func PointerOfString(s string) Pointer

func Realloc

func Realloc(p Pointer, size uintptr) Pointer

Realloc calls Realloc on the system allocator

func ReallocCap

func ReallocCap(p Pointer, size uintptr) (Pointer, uintptr)

func (Pointer) Add

func (p Pointer) Add(offset int) Pointer

Add is Pointer arithmetic.

func (Pointer) AsFloat32BE added in v0.1.4

func (p Pointer) AsFloat32BE() float32

func (Pointer) AsFloat32LE added in v0.1.4

func (p Pointer) AsFloat32LE() float32

func (Pointer) AsFloat64BE added in v0.1.4

func (p Pointer) AsFloat64BE() float64

func (Pointer) AsFloat64LE added in v0.1.4

func (p Pointer) AsFloat64LE() float64

func (Pointer) AsInt16BE added in v0.1.4

func (p Pointer) AsInt16BE() int16

func (Pointer) AsInt16LE added in v0.1.4

func (p Pointer) AsInt16LE() int16

func (Pointer) AsInt32BE added in v0.1.4

func (p Pointer) AsInt32BE() int32

func (Pointer) AsInt32LE added in v0.1.4

func (p Pointer) AsInt32LE() int32

func (Pointer) AsInt64BE added in v0.1.4

func (p Pointer) AsInt64BE() int64

func (Pointer) AsInt64LE added in v0.1.4

func (p Pointer) AsInt64LE() int64

func (Pointer) AsUint16BE added in v0.1.5

func (p Pointer) AsUint16BE() uint16

func (Pointer) AsUint16LE added in v0.1.5

func (p Pointer) AsUint16LE() uint16

func (Pointer) AsUint32BE added in v0.1.5

func (p Pointer) AsUint32BE() uint32

func (Pointer) AsUint32LE added in v0.1.5

func (p Pointer) AsUint32LE() uint32

func (Pointer) AsUint64BE added in v0.1.5

func (p Pointer) AsUint64BE() uint64

func (Pointer) AsUint64LE added in v0.1.5

func (p Pointer) AsUint64LE() uint64

func (Pointer) Byte

func (p Pointer) Byte(offset int) byte

func (Pointer) Bytes

func (p Pointer) Bytes(offset, length, capacity int) []byte

func (Pointer) Clone

func (p Pointer) Clone(offset, size int) Pointer

Clone the memory starting at offset for size number of bytes and return the new Pointer.

func (Pointer) Compare

func (p Pointer) Compare(offset, size int, to Pointer) int

Compare does a memcmp

func (Pointer) Copy

func (p Pointer) Copy(offset, size int, to Pointer)

Copy does a memcpy

func (Pointer) Equals

func (p Pointer) Equals(offset, size int, to Pointer) bool

Equals does a memequal

func (Pointer) Float32

func (p Pointer) Float32(offset int) float32

func (Pointer) Float32BE

func (p Pointer) Float32BE(offset int) float32

func (Pointer) Float32LE

func (p Pointer) Float32LE(offset int) float32

func (Pointer) Float64

func (p Pointer) Float64(offset int) float64

func (Pointer) Float64BE

func (p Pointer) Float64BE(offset int) float64

func (Pointer) Float64LE

func (p Pointer) Float64LE(offset int) float64

func (*Pointer) Free

func (p *Pointer) Free()

Free deallocates memory pointed by Pointer

func (Pointer) Hash32

func (p Pointer) Hash32(length int) uint32

func (Pointer) Hash32At

func (p Pointer) Hash32At(offset, length int) uint32

func (Pointer) Hash64

func (p Pointer) Hash64(length int) uint64

func (Pointer) Hash64At

func (p Pointer) Hash64At(offset, length int) uint64

func (Pointer) Int

func (p Pointer) Int(offset int) int

func (Pointer) Int16

func (p Pointer) Int16(offset int) int16

func (Pointer) Int16BE

func (p Pointer) Int16BE(offset int) int16

func (Pointer) Int16LE

func (p Pointer) Int16LE(offset int) int16

func (Pointer) Int24

func (p Pointer) Int24(offset int) int32

func (Pointer) Int24BE

func (p Pointer) Int24BE(offset int) int32

func (Pointer) Int24LE

func (p Pointer) Int24LE(offset int) int32

func (Pointer) Int32

func (p Pointer) Int32(offset int) int32

func (Pointer) Int32BE

func (p Pointer) Int32BE(offset int) int32

func (Pointer) Int32LE

func (p Pointer) Int32LE(offset int) int32

func (Pointer) Int40

func (p Pointer) Int40(offset int) int64

func (Pointer) Int40BE

func (p Pointer) Int40BE(offset int) int64

func (Pointer) Int40LE

func (p Pointer) Int40LE(offset int) int64

func (Pointer) Int48

func (p Pointer) Int48(offset int) int64

func (Pointer) Int48BE

func (p Pointer) Int48BE(offset int) int64

func (Pointer) Int48LE

func (p Pointer) Int48LE(offset int) int64

func (Pointer) Int56

func (p Pointer) Int56(offset int) int64

func (Pointer) Int56BE

func (p Pointer) Int56BE(offset int) int64

func (Pointer) Int56LE

func (p Pointer) Int56LE(offset int) int64

func (Pointer) Int64

func (p Pointer) Int64(offset int) int64

func (Pointer) Int64BE

func (p Pointer) Int64BE(offset int) int64

func (Pointer) Int64LE

func (p Pointer) Int64LE(offset int) int64

func (Pointer) Int8

func (p Pointer) Int8(offset int) int8

func (Pointer) Metro64

func (p Pointer) Metro64(seed uint64, offset, length int) uint64

func (Pointer) Move

func (p Pointer) Move(offset, size int, to Pointer)

Move does a memmove

func (Pointer) Pointer

func (p Pointer) Pointer(offset int) Pointer

func (Pointer) SetByte

func (p Pointer) SetByte(offset int, v byte)

func (Pointer) SetBytes

func (p Pointer) SetBytes(offset int, value []byte)

func (Pointer) SetFloat32

func (p Pointer) SetFloat32(offset int, v float32)

func (Pointer) SetFloat32BE

func (p Pointer) SetFloat32BE(offset int, v float32)

func (Pointer) SetFloat32LE

func (p Pointer) SetFloat32LE(offset int, v float32)

func (Pointer) SetFloat64

func (p Pointer) SetFloat64(offset int, v float64)

func (Pointer) SetFloat64BE

func (p Pointer) SetFloat64BE(offset int, v float64)

func (Pointer) SetFloat64LE

func (p Pointer) SetFloat64LE(offset int, v float64)

func (Pointer) SetInt

func (p Pointer) SetInt(offset int, v int)

func (Pointer) SetInt16

func (p Pointer) SetInt16(offset int, v int16)

func (Pointer) SetInt16BE

func (p Pointer) SetInt16BE(offset int, v int16)

func (Pointer) SetInt16LE

func (p Pointer) SetInt16LE(offset int, v int16)

func (Pointer) SetInt24

func (p Pointer) SetInt24(offset int, v int32)

func (Pointer) SetInt24BE

func (p Pointer) SetInt24BE(offset int, v int32)

func (Pointer) SetInt24LE

func (p Pointer) SetInt24LE(offset int, v int32)

func (Pointer) SetInt32

func (p Pointer) SetInt32(offset int, v int32)

func (Pointer) SetInt32BE

func (p Pointer) SetInt32BE(offset int, v int32)

func (Pointer) SetInt32LE

func (p Pointer) SetInt32LE(offset int, v int32)

func (Pointer) SetInt40

func (p Pointer) SetInt40(offset int, v int64)

func (Pointer) SetInt40BE

func (p Pointer) SetInt40BE(offset int, v int64)

func (Pointer) SetInt40LE

func (p Pointer) SetInt40LE(offset int, v int64)

func (Pointer) SetInt48

func (p Pointer) SetInt48(offset int, v int64)

func (Pointer) SetInt48BE

func (p Pointer) SetInt48BE(offset int, v int64)

func (Pointer) SetInt48LE

func (p Pointer) SetInt48LE(offset int, v int64)

func (Pointer) SetInt56

func (p Pointer) SetInt56(offset int, v int64)

func (Pointer) SetInt56BE

func (p Pointer) SetInt56BE(offset int, v int64)

func (Pointer) SetInt56LE

func (p Pointer) SetInt56LE(offset int, v int64)

func (Pointer) SetInt64

func (p Pointer) SetInt64(offset int, v int64)

func (Pointer) SetInt64BE

func (p Pointer) SetInt64BE(offset int, v int64)

func (Pointer) SetInt64LE

func (p Pointer) SetInt64LE(offset int, v int64)

func (Pointer) SetInt8

func (p Pointer) SetInt8(offset int, v int8)

func (Pointer) SetPointer

func (p Pointer) SetPointer(offset int, v Pointer)

func (Pointer) SetString

func (p Pointer) SetString(offset int, value string)

func (Pointer) SetUint added in v0.1.5

func (p Pointer) SetUint(offset int, v uint)

func (Pointer) SetUint16 added in v0.1.5

func (p Pointer) SetUint16(offset int, v uint16)

func (Pointer) SetUint16BE added in v0.1.5

func (p Pointer) SetUint16BE(offset int, v uint16)

func (Pointer) SetUint16LE added in v0.1.5

func (p Pointer) SetUint16LE(offset int, v uint16)

func (Pointer) SetUint24 added in v0.1.5

func (p Pointer) SetUint24(offset int, v uint32)

func (Pointer) SetUint24BE added in v0.1.5

func (p Pointer) SetUint24BE(offset int, v uint32)

func (Pointer) SetUint24LE added in v0.1.5

func (p Pointer) SetUint24LE(offset int, v uint32)

func (Pointer) SetUint32 added in v0.1.5

func (p Pointer) SetUint32(offset int, v uint32)

func (Pointer) SetUint32BE added in v0.1.5

func (p Pointer) SetUint32BE(offset int, v uint32)

func (Pointer) SetUint32LE added in v0.1.5

func (p Pointer) SetUint32LE(offset int, v uint32)

func (Pointer) SetUint40 added in v0.1.5

func (p Pointer) SetUint40(offset int, v uint64)

func (Pointer) SetUint40BE added in v0.1.5

func (p Pointer) SetUint40BE(offset int, v uint64)

func (Pointer) SetUint40LE added in v0.1.5

func (p Pointer) SetUint40LE(offset int, v uint64)

func (Pointer) SetUint48 added in v0.1.5

func (p Pointer) SetUint48(offset int, v uint64)

func (Pointer) SetUint48BE added in v0.1.5

func (p Pointer) SetUint48BE(offset int, v uint64)

func (Pointer) SetUint48LE added in v0.1.5

func (p Pointer) SetUint48LE(offset int, v uint64)

func (Pointer) SetUint56 added in v0.1.5

func (p Pointer) SetUint56(offset int, v uint64)

func (Pointer) SetUint56BE added in v0.1.5

func (p Pointer) SetUint56BE(offset int, v uint64)

func (Pointer) SetUint56LE added in v0.1.5

func (p Pointer) SetUint56LE(offset int, v uint64)

func (Pointer) SetUint64 added in v0.1.5

func (p Pointer) SetUint64(offset int, v uint64)

func (Pointer) SetUint64BE added in v0.1.5

func (p Pointer) SetUint64BE(offset int, v uint64)

func (Pointer) SetUint64LE added in v0.1.5

func (p Pointer) SetUint64LE(offset int, v uint64)

func (Pointer) SetUint8 added in v0.1.5

func (p Pointer) SetUint8(offset int, v uint8)

func (Pointer) SetUintptr

func (p Pointer) SetUintptr(offset int, v uintptr)

func (Pointer) SizeOf

func (p Pointer) SizeOf() uintptr

Sizeof returns the size of the allocation provided by the platform allocator.

func (Pointer) String

func (p Pointer) String(offset, size int) string

func (Pointer) ToFat

func (p Pointer) ToFat(length int) FatPointer

func (Pointer) Uint added in v0.1.5

func (p Pointer) Uint(offset int) uint

func (Pointer) Uint16 added in v0.1.5

func (p Pointer) Uint16(offset int) uint16

func (Pointer) Uint16BE added in v0.1.5

func (p Pointer) Uint16BE(offset int) uint16

func (Pointer) Uint16LE added in v0.1.5

func (p Pointer) Uint16LE(offset int) uint16

func (Pointer) Uint24 added in v0.1.5

func (p Pointer) Uint24(offset int) uint32

func (Pointer) Uint24BE added in v0.1.5

func (p Pointer) Uint24BE(offset int) uint32

func (Pointer) Uint24LE added in v0.1.5

func (p Pointer) Uint24LE(offset int) uint32

func (Pointer) Uint32 added in v0.1.5

func (p Pointer) Uint32(offset int) uint32

func (Pointer) Uint32BE added in v0.1.5

func (p Pointer) Uint32BE(offset int) uint32

func (Pointer) Uint32BESlow added in v0.1.5

func (p Pointer) Uint32BESlow() uint32

func (Pointer) Uint32LE added in v0.1.5

func (p Pointer) Uint32LE(offset int) uint32

func (Pointer) Uint40 added in v0.1.5

func (p Pointer) Uint40(offset int) uint64

func (Pointer) Uint40BE added in v0.1.5

func (p Pointer) Uint40BE(offset int) uint64

func (Pointer) Uint40LE added in v0.1.5

func (p Pointer) Uint40LE(offset int) uint64

func (Pointer) Uint48 added in v0.1.5

func (p Pointer) Uint48(offset int) uint64

func (Pointer) Uint48BE added in v0.1.5

func (p Pointer) Uint48BE(offset int) uint64

func (Pointer) Uint48LE added in v0.1.5

func (p Pointer) Uint48LE(offset int) uint64

func (Pointer) Uint56 added in v0.1.5

func (p Pointer) Uint56(offset int) uint64

func (Pointer) Uint56BE added in v0.1.5

func (p Pointer) Uint56BE(offset int) uint64

func (Pointer) Uint56LE added in v0.1.5

func (p Pointer) Uint56LE(offset int) uint64

func (Pointer) Uint64 added in v0.1.5

func (p Pointer) Uint64(offset int) uint64

func (Pointer) Uint64BE added in v0.1.5

func (p Pointer) Uint64BE(offset int) uint64

func (Pointer) Uint64LE added in v0.1.5

func (p Pointer) Uint64LE(offset int) uint64

func (Pointer) Uint8 added in v0.1.5

func (p Pointer) Uint8(offset int) uint8

func (Pointer) Uintptr

func (p Pointer) Uintptr(offset int) uintptr

func (Pointer) Unsafe

func (p Pointer) Unsafe() unsafe.Pointer

func (Pointer) WyHash64

func (p Pointer) WyHash64(seed uint64, offset, length int) uint64

func (Pointer) Zero

func (p Pointer) Zero(size uintptr)

Zero zeroes out the entire allocation.

type PointerSet

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

PointerSet is a hashset that uses the robinhood algorithm. This implementation is not concurrent safe.

func NewPointerSet

func NewPointerSet(size uintptr) PointerSet

NewPointerSet returns a new robinhood hashmap.

func (*PointerSet) Add

func (ps *PointerSet) Add(key uintptr, depth int) (bool, bool)

Add inserts or updates a key into the PointerSet. The returned wasNew will be true if the mutation was on a newly seen, inserted key, and wasNew will be false if the mutation was an update to an existing key.

func (*PointerSet) Close

func (ps *PointerSet) Close() error

func (*PointerSet) Delete

func (ps *PointerSet) Delete(key uintptr) (uintptr, bool)

Delete removes a key from the PointerSet.

func (*PointerSet) Grow

func (ps *PointerSet) Grow() bool

func (*PointerSet) Has

func (ps *PointerSet) Has(key uintptr) bool

Has returns whether the key exists in the Add.

func (*PointerSet) Reset

func (ps *PointerSet) Reset()

Reset clears PointerSet, where already allocated memory will be reused.

func (*PointerSet) Set

func (ps *PointerSet) Set(key uintptr) (bool, bool)

Directories

Path Synopsis
alloc
rpmalloc/lib
See https://github.com/golang/go/issues/26366.
See https://github.com/golang/go/issues/26366.
rpmalloc/lib/darwin_amd64
See https://github.com/golang/go/issues/26366.
See https://github.com/golang/go/issues/26366.
rpmalloc/lib/darwin_arm64
See https://github.com/golang/go/issues/26366.
See https://github.com/golang/go/issues/26366.
rpmalloc/lib/linux_amd64
See https://github.com/golang/go/issues/26366.
See https://github.com/golang/go/issues/26366.
collections
net
cgo
cmd

Jump to

Keyboard shortcuts

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