Abnormal programming
C++ tricks and dark magic: templates-of-templates, constexpr computation, __PRETTY_FUNCTION__ and other ways of making the language do what it wasn't quite meant to.
- Abnormal programming
Myths, superstitions and folk wisdom in game development
A look at 12 common C++ gamedev "truths" — which are myths, which are superstitions, and which are folk wisdom: the cult of pure C, the "bad good build", the cost of exceptions and RTTI, smart pointers and STL containers, polymorphism, inline assembly, template bloat, premature optimization and the curse of the Friday commit.
- Abnormal programming
A zoo of strings in your C++ code?
A big tour of C++ string types as a zoo of animals: char* and char[N], string literals, std::string and SSO, string_view, pmr::string, QString, NSString, std::wstring, frame strings, Unreal's FString, StringAtom and interning, COW strings and hash-based StringID — and where each fits in game engines.
- Abnormal programming
Be your own breakpoint
How software and hardware breakpoints work: swapping a byte for int 3 (0xCC), the x86-64 debug registers DR0–DR7 and the DR7 layout, conditional, function and temporary breakpoints, a write watchpoint via GetThreadContext, a buffer canary, and a hardware-breakpoint button right in an ImGui game editor.
- Abnormal programming
Game++. run, thread, run…
Multithreading in games: the problems with locks (deadlock, thread starvation, priority inversion in Cyberpunk 2077 and Crysis), the C++11 memory model, lock-free and atomics, spinlocks with backoff, thread pools and a task system, hitching and a read-write mutex.
- Abnormal programming
Game++. Dancing with allocators
A big tour of memory allocators in games: linear, step-back, frame, stack, pool, free list, arena, segregated, buddy, thread-cache, fibonacci, compacting, hot/cold splitting and TLSF — with code, diagrams and a benchmark.
- Abnormal programming
Game++. Cooking vectors
How vectors work in game engines and what you pay for them: capacity growth and memory fragmentation, single vs. cascaded composition, std::array, a stack-based static_vector, hybrid_vector with an SSO-like optimization, and the pitfalls of vendor pmr allocators.
- Abnormal programming
Game++. String interning
String interning (string pooling) in game engines: one copy of a string for every reference, literal interning in clang/GCC and why the trick breaks on Xbox, the danger of comparing with ==, fighting memory fragmentation, and a simple xstring implementation on hashes with reference counting.
- Abnormal programming
The heavy H[header]
How a large C++ project's full build time was cut from 15:32 to 5:16: the antivirus and explorer, heavy template headers, forward declaration, precompiled headers, PIMPL, and disabling analyzers, tests and LTO — with header build-time tables.
- Abnormal programming
How Unity gave up on their own strings
The story of Unity's COW strings: copy-on-write with partial buffer sharing and near-zero allocations, the clash with std::string's design, dangling pointers, and why the engine eventually returned to the standard library.
- Abnormal programming
Boss, it's all gone
A sequel to "Where are your bugs?": 16 Friday-night bugs from real engines — out-of-bounds writes, leaked handles on the Switch, memset on a non-trivial type, =! instead of != and alloca in a loop.
- Abnormal programming
Strings in game engines
Why std::string is shunned in engines: C-strings and NTBS, SSO and string_view, sized/pool/arena strings, shared strings and identifiers, plus SIMD config parsing.
- Abnormal programming
The magic of shader swizzle in C++
Implementing swizzle (vec.xxy, vec.zx, vec.rgb) in C++ with unions and templates: from a first copy-pasted version to a single constexpr solution and benchmarks against glm and CxxSwizzle.
- Abnormal programming
Where are your bugs?
A collection of wild bugs from real engines: a missing semicolon in Unity, a memset the compiler dropped, bitfield races in CryEngine, the most vexing parse and a dozen more — spot the bug yourself.
- Abnormal programming
When it's private but you really want public
Testing a C++ class's private members without touching the headers: from a hundred friends and #define private public to a template hack that swaps a pointer-to-member type.
- Abnormal programming
Why does the Switch SDK have three different sin functions?
Porting games to the Nintendo Switch, I found three sin implementations in the SDK — and what the disassembly showed for different optimization modes.
- Abnormal programming
A C++ enum's name at runtime
Getting a type's name and enum values at runtime in C++ without RTTI — via __PRETTY_FUNCTION__, templates and constexpr magic.