arena

package module
v0.0.0-...-1eb052f Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

README

Go Memory Arena

Introduction

this is project meant to how to do memory arena in go.

How to use

package main


import (
        "fmt
        "github.com/ElecTwix/arena"

)


func main() {
        a := arena.NewArena(1024) // 1kb arena
        p := a.Alloc(10) // 10 byte

        arena.SetMemory(p, []byte("hello world"))

        v = arena.GetMemory(p, 10) // v is []byte("hello world")

        a.Free(p) // free memory
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMemory

func GetMemory[T any](ptr unsafe.Pointer) T

func GetMemorySlice

func GetMemorySlice[T any](ptr unsafe.Pointer, size int) []T

func Next

func Next(ptr unsafe.Pointer, size int) unsafe.Pointer

func Prev

func Prev(ptr unsafe.Pointer, size int) unsafe.Pointer

func SetMemory

func SetMemory[T any](ptr unsafe.Pointer, value T)

Helper function to allocate memory

Types

type Arena

type Arena struct {
	// The size of the chunk
	// The Current
	Current   *ArenaChunk
	ChunkSize uintptr
}

func ArenaAlloc

func ArenaAlloc(chunkSize uintptr) *Arena

func (*Arena) Alloc

func (a *Arena) Alloc(size uintptr) unsafe.Pointer

func (*Arena) Free

func (a *Arena) Free()

func (*Arena) Reset

func (a *Arena) Reset()

func (*Arena) ResetCurrent

func (a *Arena) ResetCurrent()

type ArenaChunk

type ArenaChunk struct {
	Prev   *ArenaChunk
	Cursor unsafe.Pointer
	Used   uintptr
}

Jump to

Keyboard shortcuts

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