Help us shape the future of Go! Take the 2026 Go Developer Survey

handletable

package
v0.34.7 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package handletable maps opaque integer handles to Go objects.

HAL resources expose a NativeHandle() uintptr, and bind group entries carry those handles back into the backend (gputypes.BufferBinding.Buffer and so on). For Vulkan, Metal and the DX12 Texture that handle is a native object (a VkHandle, an Objective-C id, a COM pointer). Where a backend needs its own Go struct back instead (DX12 buffers, texture views and samplers, GLES texture views), the handle must not be the struct's address: converting a Go pointer to uintptr and back breaks rule 6 of the unsafe.Pointer rules (the uintptr does not keep the object alive and the GC may move or free it), and checkptr, which go test -race enables, reports it as a fatal error.

A Table hands out a fresh integer per object and resolves it through a map. The map holds the object alive until Remove, so a resource must Remove its handle when it is destroyed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Table

type Table[T any] struct {
	// contains filtered or unexported fields
}

Table maps handles to *T. The zero value is an empty table ready to use. A Table must not be copied after first use.

func (*Table[T]) Add

func (t *Table[T]) Add(v *T) uintptr

Add registers v and returns its handle. Handles are never 0 (0 means "no resource" in the HAL binding types) and increase monotonically, so a removed handle is not handed out again until the counter wraps.

func (*Table[T]) Get

func (t *Table[T]) Get(h uintptr) (*T, bool)

Get returns the object registered under h. It reports false for 0, for a handle this table never issued and for a removed handle.

func (*Table[T]) Len

func (t *Table[T]) Len() int

Len returns the number of registered objects.

func (*Table[T]) Remove

func (t *Table[T]) Remove(h uintptr)

Remove drops h. Removing 0, an unknown or an already removed handle does nothing, so a resource's Destroy may call it more than once.

Jump to

Keyboard shortcuts

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