Exploring Swift Memory Layout
summary
A small program in Swift 3 and Xcode 8 crawls live process memory, using mach_vm_read_overwrite for safe reads, malloc_size and dladdr to size and name regions, then emits Graphviz to visualize object graphs; it runs on x86-64 macOS and produces PDFs that match expectations. Key findings: Swift structs and classes lay out like C/C++ with padding, arrays are reference-backed, protocol values are five words (three inline + metadata + witness table), and enums pack variably; the tool works and reveals surprising boxing thresholds.
AI-written summary · about
chapters (25)
- 0:00Introduction
- 0:31About Me
- 6:19Memory - Big Picture
- 9:47Dumping Memory
- 14:50Pointers are Integers
- 16:51Bad Pointers
- 19:43Safe Reads
- 20:17How Much to Read?
- 22:23Name Mangling
- 23:48Strings
- 25:29Output
- 26:05Graphviz
- 27:23Memory Layouts
- 28:19C structs
- 30:17C++ classes
- 36:03Swift Types
- 42:26Objective-C Classes
- 43:30Swift Classes
- 44:11Method Calls
- 44:42Subclasses
- 45:14Arrays
- 46:15Protocols
- 49:38Protocol Method Call
- 50:41Enums
- 53:28Wrapping Up








