Skip to content
/ weak Public

Manual Memory Management in Go. Slower, but no CGO required!

Notifications You must be signed in to change notification settings

intervinn/weak

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

implements manual memory allocation using syscalls, memory leaks guaranteed!

this library is expected to be more unsafe and slow due to usage of syscalls

almost everything in the library is stack-allocated except for binary endings used to turn values into byte arrays, but some day ill find a better alternative

works only on mac and linux

usage

chunks

chunks are just a wrapping around allocated memory which you can write and read from

unlike other implementations of io.Reader/io.Writers, it doesn't append to slice, but writes from beginning

package main

import (
	"encoding/binary"

	"github.com/intervinn/weak"
)

func main() {
	c, err := weak.Alloc(weak.SizeOf[int32]())
	if err != nil {
		panic(err)
	}

	var val int32
	binary.Write(c, binary.NativeEndian, int32(69420)) // 69420
	binary.Read(c, binary.NativeEndian, &val)
	println(val)

	c.Free()
	//binary.Read(c, binary.NativeEndian, &val) this segfaults
}

boxes

boxes wrap around chunks to hold a single instance of datatype

import "github.com/intervinn/weak"

func main() {
	b, err := weak.NewBox[float32]()
	if err != nil {
		panic(err)
	}

	b.Set(3.14)
	println(b.Value()) // +3.140000e+000 but thats println issue

	b.Free()
}

About

Manual Memory Management in Go. Slower, but no CGO required!

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages