Welcome to Nimrod’s Coding Lab!

  • Here is a personal programming-related blog.
  • Want to know about me?
  • To contact me, use one of the methods below.

Virtual Function Costs

Measuring real performance cost of C++ virtual functions: vtable lookup overhead, branch misprediction, devirtualization, and when to avoid virtual dispatch.

November 26, 2024 · 6 min · Nimrod

C++ Type Dispatch

Techniques for type dispatch in C++: tag dispatch, if constexpr, std::variant with std::visit, and how to choose the right approach for your use case.

November 10, 2024 · 8 min · Nimrod

How to Resolve Macro Name Collisions

Practical techniques to resolve C/C++ macro name collisions between system headers and user code: undef, parenthesization, and inline function workarounds.

February 25, 2024 · 3 min · Nimrod

C++: How to Access Private Members VALIDLY

A surprisingly valid C++ technique to access private class members using explicit template instantiation, with analysis of what the standard actually permits.

August 10, 2022 · 3 min · Nimrod

C++: Elegant Ways to Map Runtime Values to Types

How to elegantly dispatch from runtime values to compile-time types in C++ using techniques like std::variant, type lists, and template metaprogramming.

July 31, 2022 · 3 min · Nimrod

Algorithms behind Popcount

Three classical popcount algorithms: from naive bit-twiddling to the Hamming weight trick, plus how modern CPUs accelerate it with POPCNT and AVX-512.

July 17, 2022 · 6 min · Nimrod

C++ Virtual Table Tables(VTT)

A detailed walkthrough of how C++ virtual table of tables (VTT) works for classes with virtual base classes, with concrete memory layout examples.

May 18, 2022 · 7 min · Nimrod

What does C++ Object Layout Look Like?

Visual walkthrough of C++ object memory layout: member ordering, padding, base class subobjects, vtable pointers, and how multiple inheritance affects layout.

May 8, 2022 · 12 min · Nimrod

A Subtle Bug Before C++17

A deep dive into a subtle C++ performance bug: why over-aligned dynamic memory allocation was undefined before C++17 and how alignas interacts with operator new.

April 21, 2022 · 3 min · Nimrod

Iyengar111 NanoLog Source Code Reading

Deep dive into NanoLog, an extremely fast C++ logging library: how it achieves nanosecond-scale latency with lock-free queues and cache-line alignment.

April 9, 2022 · 11 min · Nimrod