offheap

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: BSD-3-Clause Imports: 1 Imported by: 0

README

offheap

Allocate offheap memory in Go programs

GitHub

Project Overview

Package offheap provides a simple library for allocating offheap memory in Go programs. Doing so is useful for allocating large []byte that should not be managed by the garbage collector.

Getting Started

The offheap package can be installed by running

go get github.com/shoenig/offheap
Example Usage
package main

import (
    "fmt"

    "github/shoenig/offheap"
)

func main() {
    var m offheap.Memory
    var e error

    // allocate 5 MB
    if m, e = offheap.New(5 * 1024 * 1024); e != nil {
        panic(e)
    }
    fmt.Println("m[0]", m[0])

    m[0] = 42
    fmt.Println("m[0]", m[0])

    if e = m.Unmap(); e != nil {
        panic(e)
    }
    fmt.Println("finished")
}

Contributing

Package offheap is pretty minimalist, and so it's basically feature complete. Bug fixes and good ideas though are always welcome, please just file an issue.

License

The github.com/shoenig/offheap module is open source under the BSD-3-Clause license.

Documentation

Overview

Package offheap provides a way to use system memory directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Memory

type Memory []byte

Memory represents a private anonymous mmap in-memory-only file that your program can use to read and write bytes. This allows your program to use very large amounts of memory without the Go runtime trying to garbage collect it.

func New

func New(bytes int64) (Memory, error)

New creates an offheap Memory slice of the specified number of bytes.

func (Memory) Unmap

func (m Memory) Unmap() error

Unmap will delete the offheap Memory slice. Any usage of the Memory afterwords will cause a panic.

Jump to

Keyboard shortcuts

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