arena

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package arena is a bump allocator with a linked list of fixed-size blocks. It mirrors cpython/Python/pyarena.c and serves the compiler pipeline (parser, AST, symtable, codegen) where many small nodes share a single lifetime.

The arena is not safe for concurrent use. Callers serialize externally, the same as CPython.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arena

type Arena struct {
	// contains filtered or unexported fields
}

Arena is a bump allocator. The zero value is not usable; call New.

CPython: Python/pyarena.c:L43 _arena

func New

func New() *Arena

New returns an arena with one preallocated block.

CPython: Python/pyarena.c:L125 _PyArena_New

func (*Arena) AddObject

func (a *Arena) AddObject(obj any) error

AddObject registers obj so it is retained until Free is called. The error return mirrors the C call shape; in practice the value is always nil.

CPython: Python/pyarena.c:L200 _PyArena_AddPyObject

func (*Arena) Free

func (a *Arena) Free()

Free drops every block and tracked object, so the GC can reclaim them. The arena must not be used after Free.

CPython: Python/pyarena.c:L154 _PyArena_Free

func (*Arena) Malloc

func (a *Arena) Malloc(n int) []byte

Malloc returns a byte slice of length n carved out of the current block, allocating a new block if needed. The slice is capped so callers cannot append into the next allocation. n is rounded up to the alignment boundary; the returned slice has the rounded length, matching what _PyArena_Malloc hands out in C.

CPython: Python/pyarena.c:L177 _PyArena_Malloc

Jump to

Keyboard shortcuts

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