
unsafe.Pointer in Go: The 4 Patterns the Rules Actually Allow
unsafe.Pointer has four legal conversion patterns. Here they are, the uintptr lifetime trap, and where Go's standard library uses them.
Tag archive

unsafe.Pointer has four legal conversion patterns. Here they are, the uintptr lifetime trap, and where Go's standard library uses them.

Bound method values as callbacks, method expressions that take the receiver as an argument, and where each one belongs in real Go handler wiring.

Compile Go regexes once at package level, trust RE2's no-backtracking guarantee, and know when a hand-written scan wins.

Move Go sorting off sort.Slice and onto slices.Sort, SortFunc, and cmp.Compare. What changes, what gets faster, and the stability call.

bufio.Scanner silently caps lines at 64KB and stops. Here is why it happens, how Buffer() lifts the ceiling, and when to drop Scanner for Reader.

Stop your tickers, stop leaking time.After in loops, and learn why Go 1.23 quietly deleted the drain-before-Reset dance.

Three tiny io helpers that let Go stream, hash, and cap payloads without ever buffering the whole thing in memory.

Go 1.22 gave the standard library method-aware routing and path wildcards. Here is how PathValue, precedence, and {$} actually behave.

How Go's monotonic clock makes Sub immune to NTP jumps, why marshaling silently strips it, and the timing bugs that follow.

One method each, yet io.Reader and io.Writer wire up gzip, hashing, network, and files with no glue code. Here is why Go kept them this small.

In-place delete, insert, filter, and reverse in Go — plus the aliasing and memory-retention traps, and where the slices package covers you now.

Design Go types so the zero value already works. sync.Mutex and bytes.Buffer do it. Here is how to copy the habit and when a constructor still earns its place.