mm

package
v0.0.0-...-a8a18e3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: Unlicense Imports: 7 Imported by: 0

README

Experimental memory-allocator generator, based on https://www.youtube.com/watch?v=mCrVYYlFTrA.

NB: This is only a proof-of-concept implementation, nothing else. It has bugs, problems, it could be smarter, not as nice to use etc... So don't use this in production nor anywhere... it's just a proof-of-concept, nothing else.

To generate an example: go run gen.go.

Notes: It rarely makes sense to use such custom-allocators in Go. If you need to use it, you might be better off implementing that thing in some other language (e.g. C++, D, Rust, C etc.).

Documentation

Index

Constants

View Source
const FallbackDef = `` /* 919-byte string literal not displayed */
View Source
const PlatformAlignment = 4 // todo: add build tags

Variables

This section is empty.

Functions

func Generate

func Generate(def string, specs map[string]*Spec) ([]byte, error)

Types

type Aligned

type Aligned struct{}

func (Aligned) Alignment

func (m Aligned) Alignment() int

func (Aligned) Alloc

func (m Aligned) Alloc(size int) unsafe.Pointer

func (Aligned) Dealloc

func (m Aligned) Dealloc(p unsafe.Pointer) bool

func (Aligned) Realloc

func (m Aligned) Realloc(p *unsafe.Pointer, size int) bool

type Allocator

type Allocator interface {
	Alignment() int
	Alloc(size int) unsafe.Pointer
}

type Deallocator

type Deallocator interface {
	Dealloc(p unsafe.Pointer) bool
}

type Emptyer

type Emptyer interface {
	Empty() bool
}

type Error

type Error struct {
	Message   error
	Generated []byte
}

func (*Error) Error

func (err *Error) Error() string

type Malloc

type Malloc struct{}

func (Malloc) Alignment

func (m Malloc) Alignment() int

func (Malloc) Alloc

func (m Malloc) Alloc(size int) unsafe.Pointer

func (Malloc) Dealloc

func (m Malloc) Dealloc(p unsafe.Pointer) bool

func (Malloc) Realloc

func (m Malloc) Realloc(p *unsafe.Pointer, size int) bool

type Owner

type Owner interface {
	Owns(p unsafe.Pointer) bool
}

type Reallocator

type Reallocator interface {
	Realloc(p *unsafe.Pointer, size int) bool
}

type Spec

type Spec struct {
	Type      string
	Alignment int
	Dealloc   bool
	Owns      bool
	Empty     bool
}

func SpecFor

func SpecFor(v Allocator) *Spec

Directories

Path Synopsis
DO NOT EDIT GENERATED CODE
DO NOT EDIT GENERATED CODE

Jump to

Keyboard shortcuts

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