Swift's Pointy Bits: Unsafe Swift & Pointer Types
summary
Covers Swift’s eight unsafe pointer types (typed vs raw, mutable vs immutable) and buffer pointers, shows interop with a C API (SKSearchFindMatches) and two optimizations: replacing a zeroed array with manual UnsafeMutablePointer.allocate plus defer deallocate to skip needless initialization, and using withUnsafeMutableBufferPointer to eliminate per-access bounds checks — both trade safety for measurable speed. Emphasizes strict rules: never escape pointers from withUnsafe... or rely on implicit ampersand conversions, and explains bind vs assumingBound semantics and when behavior becomes undefined.
AI-written summary · about
chapters (6)
- 0:00Intro
- 0:12Swift's Pointy Bits
- 4:07Unexpected Behavior
- 7:45Unsafe Pointer Types
- 11:00Mutable
- 19:59Really Not Safe at All
related talks
28mUsability Meets Performance in Swift
20mSwift WTF: Weirdness, traps, and fixes
44mSo You Think You Know Swift
34mSo You Think You Know Swift?
20mHow Not to Write Swift
58mSwift: safety, ergonomics, productivity and legacy preservation
32mBeyond the &: A Future for Native Smart Pointers in Rust
39mSwift and You
