Breaking Dependencies - C++ Type Erasure - The Implementation Details
summary
Shows two ~20 line implementations for owning and non-owning wrappers, then builds a real shape wrapper with a templated constructor, clone-based copy, and an optional Small Buffer Optimization (128 bytes) to avoid allocations. Benchmarks use 10,000 randomly chosen shapes and 25,000 cheap translate ops, finding about a 10% win with SBO. Also demonstrates manual virtual dispatch (≈10 lines) as an alternative to vtables and explains move/copy semantics, storage-policy tradeoffs, and when each technique actually improves performance.
AI-written summary · about
chapters (27)
- 0:00Introduction
- 1:42Motivation
- 5:02Implementation
- 11:52Implementation Details
- 15:22Shape Wrapper
- 17:09Friends
- 19:31Clone
- 20:25Copy
- 25:37No pointers
- 26:46Architectural Boundaries
- 28:57Test Code
- 29:28Extended Model
- 32:43Performance
- 33:27Explanation
- 35:11Performance Optimization
- 36:05Small Buffer
- 39:39Clone Function
- 42:03destructor
- 42:37copyswap
- 44:05template parameters
- 46:19too deep
- 46:42simple
- 48:11manual virtual dispatch
- 50:36code
- 55:03benchmark
- 56:07conclusion
- 57:54Questions
related talks
01h 03mType Erasure - The Implementation Details
01h 03mBreaking Dependencies: type erasure - a design analysis
01h 02mBreaking Dependencies: Type Erasure - A Design Analysis
44mPragmatic Type Erasure: Solving OOP Problems w/ Elegant Design Pattern
56mC++ Relocation - How to Achieve Blazing Fast Save and Restore and More!
01h 01mEmbracing PODs Safely Until They Die
01h 05mExpressing Implementation Sameness and Similarity - Polymorphism in Modern C++
01h 01mEmbracing (and also Destroying) Variant Types Safely
