Skip to content

offheap - allocate system memory off heap in Go

License

Notifications You must be signed in to change notification settings

shoenig/offheap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.