Skip to content
Try Kata

mem.buf

A typed allocation with capacity, underneath the array’s live-element count.

All modules · Writing docstrings

import core.lifecycle.{Drop}
import mem.ptr.{Ptr}
import mem.allocator.{heap}
kind Buf[T]

A pointer and capacity. Capacity alone does not mean all slots are initialized.

Source, line 8

ptr: Ptr[T]

Typed pointer to the allocation.

Source, line 10

cap: Int

Number of allocated slots.

Source, line 12

impl Buf[@T]

Source, line 15

func read(self, index: Int): T

Read a slot through the typed pointer; callers track which slots are live.

Source, line 17

func write(self, index: Int, val: T)

Write a typed value into the backing allocation.

Source, line 22

func grow(self)

Double capacity, or allocate four slots when empty, and move the contents.

Source, line 27

impl Buf[@T] as Drop

Source, line 35

func drop(self)

Free the backing allocation. Aliases must not use it afterward.

Source, line 37