C++ - Reddit
224 subscribers
48 photos
8 videos
24.7K links
Stay up-to-date with everything C++!
Content directly fetched from the subreddit just for you.

Join our group for discussions : @programminginc

Powered by : @r_channels
Download Telegram
A virtual pointer pattern for dynamic resolution in C++ — years in production

I've been working on Olex2, a crystallography software package, for over 20 years. At some point I needed pointers whose target wasn't a fixed address but a runtime decision — "whatever is currently the active object of this type."

The result was olx_vptr — a virtual pointer where resolution is delegated to a user-defined get_ptr():

https://github.com/pcxod/olex2/blob/master/sdl/olxvptr.h

The calling code uses natural pointer syntax and knows nothing about how resolution happens. A concrete use looks like this:

struct VPtr : public olx_virtual_ptr<TXFile> {

virtual IOlxObject *get_ptr() const;

};

olx_vptr<TXFile> thip(new VPtr());

lib->Register(
new TFunction<TXFile>(thip, &TXFile::LibGetFormula, "GetFormula", .....

(https://github.com/pcxod/olex2/blob/master/xlib/xfiles.cpp#L1427)

Single virtual dispatch, fully type-safe, open to any resolution strategy.

I'm surprised this pattern never made it into the standard or common literature. Has anyone seen something similar? Would there be interest in a more formal writeup?

https://redd.it/1spvxx6
@r_cpp
I built a calm, readable system monitor for Linux (Qt6, C++20, open source)

Most Linux system monitors end up in one of two places: they feel ancient and cramped, or they show everything at once and become visual noise. I wanted something in between, genuinely useful but still pleasant to look at for more than ten seconds. So I built archvital.

It has a compact Overview page for the numbers that matter most, plus dedicated pages for CPU, GPU, Memory, Disk, Network, Tasks, and a Diagnostics page for common health checks. There is a Settings page for theme colors and section visibility, and preferences are saved through QSettings so the app remembers your layout between sessions.

The whole thing is built on Qt6 and C++20 with custom sidebar, card, sparkline, and bar components. No extra widget library beyond Qt itself.

The project is already daily driveable but still actively evolving. Screenshots are in the repo. If you try it and something looks wrong or reads oddly, that is exactly the kind of feedback I am looking for.

github.com/T9Tuco/archvital

https://redd.it/1sq6siu
@r_cpp
SIMD IPv6 lookup vs Patricia trie: surprising real-world results

I’ve been working on a C++ implementation of a SIMD-accelerated IPv6 longest-prefix-match (LPM) structure based on the PlanB paper (linearized B+-tree + AVX-512).



On synthetic workloads, the results were as expected:

\~20× faster than a naive Patricia trie.



But when I switched to a real BGP table (RIPE RIS rrc00, \~254K IPv6 prefixes), I got a surprising result:



A simple Patricia trie can actually match or even outperform the SIMD-based tree.



Numbers (single core, Ice Lake laptop):

\- SIMD tree: \~65–137 MLPS

\- Patricia: \~95 MLPS median



The reason seems to be cache locality and early exits:

\- Patricia often resolves lookups after just a few pointer hops in hot regions of the address space

\- The SIMD tree always pays a fixed traversal cost (depth \~7)



So even though the SIMD approach is more “theoretically efficient”, real-world prefix distribution and access patterns change the outcome quite a bit.



I’m curious if others have observed similar effects in routing / packet processing systems, or when comparing structures like PopTrie / CP-Trie.



Repo (MIT, includes benchmarks + real BGP reproduction):

https://github.com/esutcu/planb-lpm

https://redd.it/1sqe08e
@r_cpp
I am new to C++, is it just me or is the checklist kinda crazy? How often do you encounter these or plan on making use of them like the newer C++26 features like contracts? Looking for more experienced dev opinions...

I know Python and have been binging C++ for a couple of days now from scratch. C++ feels like a language where you gradually discover a huge checklist of "STATE YOUR INTENT" due to years of probably layering on things to shore up its weaknesses of memory/type safety etc. Like I get it, it's how C++ was designed for things to be explicit and it's like the English language where you don't need to know every word and in this case, feature, but every line of code makes me feel I'm asking a gajillion questions.

So far I have jotted down some stuff that took me awhile to digest...

* const
* constexpr
* [[nodiscard]]
* std::expected
* delete("reason")
* smart pointers
* zero-initialization curly brackets
* structured bindings
* assert
* static assert
* contracts

So I guess I'm not very familiar with the ecosystem or ever worked with other C++ code. Like is this good or bad? I would think it's very safe but do and should people code actually C++ like this? I don't have a frame of reference to relate to and I don't know if the C++ community is going to jump on things like C++26's contracts or reject it. What's the current attitude? If you were a teammate, would you love or hate to see something like this?

[[nodiscard]] constexpr std::expected<int, Error> GetHP(const std::unique_ptr<Player>& player)
{
assert(player);
if (!player) return std::unexpected(Error::NullPlayer);
const auto [hp, alive] = std::pair{player->hp, player->hp > 0};
static_assert(sizeof(int) == 4);
return alive ? hp : 0;
}

https://redd.it/1sqhobx
@r_cpp
Avoiding per-cell std::string allocation in a vectorized filter

Writing a small columnar query engine and hit a string-copy trap in the filter operator. The fix turned out to be
measurable so I thought I'd share.

Naive version: output chunk built cell-by-cell.

  for (idx_t i = 0; i < input.size(); i++) {
if (!matches[i]) continue;
for (idx_t c = 0; c < num_cols; c++)
result.SetValue(c, out, input.GetValue(c, i));
out++;
}


GetValue/SetValue go through a tagged Value type, and for VARCHAR they each allocate a fresh std::string. 1M
rows with a few VARCHAR columns means millions of allocations on a single filter pass.

Vectorized version: build a uint32_t sel[] of matching row indices, then per column copy with the typed pointer.

  auto *s = src.GetData<int64_t>();
auto *d = dst.GetData<int64_t>();
for (idx_t i = 0; i < n; i++) d[i] = s[sel[i]];


Trivial for numeric types. For VARCHAR it's trickier: string_t is a 16-byte type, inline for short strings, a
pointer to a heap-allocated payload for longer ones. Copying the 16 bytes is cheap. The problem is that the
long-string pointer aims at the source vector's string heap. Let src go out of scope and dst's strings point at freed
memory.

The string heap (VectorStringBuffer) is already owned via shared_ptr<VectorBuffer>. Fix is a setter that makes dst
adopt src's heap:

  auto *s = src.GetData<string_t>();
auto *d = dst.GetData<string_t>();
for (idx_t i = 0; i < n; i++) d[i] = s[sel[i]];
dst.SetAuxiliaryPtr(src.GetAuxiliaryPtr()); // dst keeps src's heap alive


No string copies. Refcount bumps once per vector, not once per cell.

A WHERE ... GROUP BY region query on 1M rows went from 894 ms to ~150 ms. Roughly 100 ms of that was this change
alone; the rest was unrelated parallelism on another pass.

Question for the sub: is there a standard name for this pattern? "Copy handles that reference an upstream buffer,
retain the buffer as long as any handle lives." Arrow solves the same problem internally. shared_ptr<Buffer>
adoption feels manual. Curious what the idiomatic C++ answer is.

Repo if anyone wants the full context: https://github.com/SouravRoy-ETL/slothdb

https://redd.it/1sqj7ze
@r_cpp
New C++ Conference Videos Released This Month - April 2026 (Updated To Include Videos Released 2026-04-13 - 2026-04-19)

**CppCon**

2026-04-13 - 2026-04-19

* Persistence Squared: Persisting Persistent Data Structures - Juan Pedro Bolivar Puente - [https://youtu.be/HmmRVdYMP-g](https://youtu.be/HmmRVdYMP-g)
* CTRACK: C++ Performance Tracking and Bottleneck Discovery - Grischa Hauser - [https://youtu.be/en4OQvZePqg](https://youtu.be/en4OQvZePqg)
* From C+ to C++: Modernizing a GameBoy Emulator - Tom Tesch - [https://youtu.be/ScmhRNSrRP4](https://youtu.be/ScmhRNSrRP4)
* Leverage AI Agents to Refactor and Modernize C++ Code - Jubin Chheda - [https://youtu.be/vAySFnu-Z18](https://youtu.be/vAySFnu-Z18)
* Lightning Talk: Algebraic Path Problems Done Quick: Or how to find the best\* path from one talk to another - Stefan Ivanov - [https://youtu.be/Fcun7lDfTRQ](https://youtu.be/Fcun7lDfTRQ)

2026-04-06 - 2026-04-12

* Rust/C++ Interop Challenges - Victor Ciura - [https://youtu.be/8xqhSy539Pc](https://youtu.be/8xqhSy539Pc)
* groov: Asynchronous Handling of Special Function Registers - Michael Caisse - [https://youtu.be/TjSL-XCyUJY](https://youtu.be/TjSL-XCyUJY)
* Clean code! Horrible Performance? - Sandor Dargo - [https://youtu.be/nLts4S8xSd4](https://youtu.be/nLts4S8xSd4)
* Beyond the Big Green Button: Demystifying the Embedded Build Process - Morten Winkler Jørgensen - [https://youtu.be/UekVdzMCAa0](https://youtu.be/UekVdzMCAa0)
* C++: Some Assembly Required - Matt Godbolt - [https://youtu.be/zoYT7R94S3c](https://youtu.be/zoYT7R94S3c)

2026-03-30 - 2026-04-05

* How to Build Type Traits in C++ Without Compiler Intrinsics Using Static Reflection - Andrei Zissu - [https://youtu.be/EcqiwhxKZ4g](https://youtu.be/EcqiwhxKZ4g)
* Beyond Sequential Consistency: Unlocking Hidden Performance Gains - Christopher Fretz - CppCon 2025 - [https://youtu.be/6AnHbZbLr2o](https://youtu.be/6AnHbZbLr2o)
* Dynamic Asynchronous Tasking with Dependencies - Tsung-Wei (TW) Huang - CppCon 2025 - [https://youtu.be/6Jd9Zyl9SDc](https://youtu.be/6Jd9Zyl9SDc)
* Work Contracts in Action: Advancing High-performance, Low-latency Concurrency in C++ - Michael Maniscalco - CppCon 2025 - [https://youtu.be/5ghAa7B5bF0](https://youtu.be/5ghAa7B5bF0)
* Constexpr STL Containers: Why C++20 Still Falls Short - Sergey Dobychin - CppCon 2025 - [https://youtu.be/Py4GJaCHwkA](https://youtu.be/Py4GJaCHwkA)

**C++Online**

2026-04-13 - 2026-04-19

* Suspend and Resume: How C++20 Coroutines Actually Work - Lieven de Cock - [https://youtu.be/SOSn6Ich60A](https://youtu.be/SOSn6Ich60A)
* Building High-Performance Distributed Systems in Modern C++ - Real-World Patterns with Boost.Asio & Beast - Samaresh Kumar Singh - [https://youtu.be/V9pKPug3xbo](https://youtu.be/V9pKPug3xbo)

2026-04-06 - 2026-04-12

* Mastering C++ Clocks: A Deep Dive into std::chrono - Sandor DARGO - [https://youtu.be/ytI6pzT1Opk](https://youtu.be/ytI6pzT1Opk)

2026-03-30 - 2026-04-05

* Is AI Destroying Software Development? - David Sankel - C++Online 2026 - [https://youtu.be/Ek32ZH3AI3k](https://youtu.be/Ek32ZH3AI3k)
* From Hello World to Real World - A Hands-On C++ Journey from Beginner to Advanced - Workshop Preview - Amir Kirsh - [https://youtu.be/2zhW-tL2UXs](https://youtu.be/2zhW-tL2UXs)
* Workshop Preview: C++ Software Design - Klaus Iglberger - [https://youtu.be/VVQN-fkwqlA](https://youtu.be/VVQN-fkwqlA)
* Workshop Preview: Essential GDB and Linux System Tools - Mike Shah - [https://youtu.be/ocaceZWKm\_k](https://youtu.be/ocaceZWKm_k)
* Workshop Preview: Concurrency Tools in the C++ Standard Library - A Hands-On Workshop - Mateusz Pusz - [https://youtube.com/live/Kx9Ir1HBbwY](https://youtube.com/live/Kx9Ir1HBbwY)
* Workshop Preview: Mastering std::execution (Senders/Receivers) - A Hands-On Workshop - Mateusz Pusz - [https://youtube.com/live/bsyqh\_bjyE4](https://youtube.com/live/bsyqh_bjyE4)
* Workshop Preview: How C++ Actually Works - Hands-On With Compilation, Memory, and Runtime - Assaf Tzur-El - [https://youtube.com/live/L0SSRRnbJnU](https://youtube.com/live/L0SSRRnbJnU)
* Workshop Preview:
Jumpstart to C++ in Audio - Learn Audio Programming & Create Your Own Music Plugin/App with the JUCE C++ Framework - Jan Wilczek - [https://youtube.com/live/M3wJN0x8cJw](https://youtube.com/live/M3wJN0x8cJw)
* Workshop Preview: AI++ 101 - Build an AI Coding Assistant in C++ & AI++ 201 - Build a Matching Engine with Claude Code - Jody Hagins - [https://youtube.com/live/Vx7UA9wT7Qc](https://youtube.com/live/Vx7UA9wT7Qc)
* Workshop Preview: Stop Thinking Like a Junior - The Soft Skills That Make You Senior - Sandor DARGO - [https://youtube.com/live/nvlU5ETuVSY](https://youtube.com/live/nvlU5ETuVSY)
* Workshop Preview: Splice & Dice - A Field Guide to C++26 Static Reflection - Koen Samyn - [https://youtube.com/live/9bSsekhoYho](https://youtube.com/live/9bSsekhoYho)

**ADC**

2026-04-13 - 2026-04-19

* Building Better Software through Cross-Functional Collaboration - Matt Morton - [https://youtu.be/l5RxH7pZVpw](https://youtu.be/l5RxH7pZVpw)
* Accelerate UI Development - Seamless Designer-Developer Collaboration with Web Tools - Ryan Wardell - [https://youtu.be/HXwjKm5Vu08](https://youtu.be/HXwjKm5Vu08)

2026-04-06 - 2026-04-12

* Hacking Handhelds for Creative Audio - Building Music Applications for the New Nintendo 3DS - Leonardo Foletto - [https://youtu.be/x-9lDvfAKd0](https://youtu.be/x-9lDvfAKd0)
* Helicopter View of Audio ML - Martin Swanholm - [https://youtu.be/TxQ4htrS2Po](https://youtu.be/TxQ4htrS2Po)
* PhilTorch: Accelerating Automatic Differentiation of Digital Filters In PyTorch - How to evaluate differentiable filters 1000 times faster in PyTorch. - Chin-Yun Yu - [https://youtu.be/Br5QhU\_08Po](https://youtu.be/Br5QhU_08Po)

2026-03-30 - 2026-04-05

* Creating from Legacy Code - A Case Study of Porting Legacy Code from Exponential Audio - Harriet Drury - [https://youtu.be/rjafXQwCz4w](https://youtu.be/rjafXQwCz4w)
* Designing an Audio Live Coding Environment - Corné Driesprong - [https://youtu.be/Jw8x2uMgFnc](https://youtu.be/Jw8x2uMgFnc)
* How To Successfully Develop Software Products - Olivier Petit & Alistair Barker - [https://youtu.be/vymlQFopbp0](https://youtu.be/vymlQFopbp0)

**Meeting C++**

2026-04-06 - 2026-04-12

* The Misra C++:2023 Guidelines - Richard Kaiser - [https://www.youtube.com/watch?v=TRz-WXgADuI](https://www.youtube.com/watch?v=TRz-WXgADuI)
* Applied modern C++: efficient expression evaluator with type erasure - Olivia Quinet - [https://www.youtube.com/watch?v=66WtE\_7wE1c](https://www.youtube.com/watch?v=66WtE_7wE1c)

2026-03-30 - 2026-04-05

* Building C++: It Doesn't Have to be Painful! - Nicole Mazzuca - Meeting C++ 2025 - [https://www.youtube.com/watch?v=ExSlx0vBMXo](https://www.youtube.com/watch?v=ExSlx0vBMXo)
* int != safe && int != ℤ - Peter Sommerlad - Meeting C++ 2025 - [https://www.youtube.com/watch?v=YyNE6Y2mv1o&pp=0gcJCdkKAYcqIYzv](https://www.youtube.com/watch?v=YyNE6Y2mv1o&pp=0gcJCdkKAYcqIYzv)

**using std::cpp**

2026-03-30 - 2026-04-05

* Learning C++ as a newcomer - Berill Farkas - [https://www.youtube.com/watch?v=nsMl54Dvm24](https://www.youtube.com/watch?v=nsMl54Dvm24)
* C++29 Library Preview : A Practitioners Guide - Jeff Garland - [https://www.youtube.com/watch?v=NqpLxkatkt4](https://www.youtube.com/watch?v=NqpLxkatkt4)
* High frequency trading optimizations at Pinely - Mikhail Matrosov - [https://www.youtube.com/watch?v=qDhVrxqb40c](https://www.youtube.com/watch?v=qDhVrxqb40c)
* Don’t be negative! - Fran Buontempo - [https://www.youtube.com/watch?v=jqLEFPDXZ-o](https://www.youtube.com/watch?v=jqLEFPDXZ-o)
* Cross-Platform C++ AI Development with Conan, CMake, and CUDA - Luis Caro - [https://www.youtube.com/watch?v=jnKeUE2C8\_I](https://www.youtube.com/watch?v=jnKeUE2C8_I)
* Building a C++23 tool-chain for embedded systems - José Gómez López - [https://www.youtube.com/watch?v=AlNnd0QARS8](https://www.youtube.com/watch?v=AlNnd0QARS8)
* Space Invaders: The Spaceship Operator is upon us - Lieven de Cock - [https://www.youtube.com/watch?v=9niOq1kr61Y](https://www.youtube.com/watch?v=9niOq1kr61Y)
* Same C++, but quicker to the finish line - Daniela Engert -
[https://www.youtube.com/watch?v=9ijIocn\_xzo](https://www.youtube.com/watch?v=9ijIocn_xzo)
* Having Fun With C++ Coroutines - Michael Hava - [https://www.youtube.com/watch?v=F9ffx7HvyrM](https://www.youtube.com/watch?v=F9ffx7HvyrM)
* The road to 'import boost': a library developer's journey into C++20 modules - Rubén Pérez Hidalgo - [https://www.youtube.com/watch?v=hD9JHkt7e2Y](https://www.youtube.com/watch?v=hD9JHkt7e2Y)
* C++20 and beyond: improving embedded systems performance - Alfredo Muela - [https://www.youtube.com/watch?v=SxrC-9g6G\_o](https://www.youtube.com/watch?v=SxrC-9g6G_o)
* Supercharge Your C++ Project: 10 Tips to Elevate from Repo to Professional Product - Mateusz Pusz - [https://www.youtube.com/watch?v=DWXlyOd\_z88](https://www.youtube.com/watch?v=DWXlyOd_z88)
* Compiler as a Service: C++ Goes Live - Aaron Jomy, Vipul Cariappa - [https://www.youtube.com/watch?v=jMO5Usa26cg](https://www.youtube.com/watch?v=jMO5Usa26cg)
* The CUDA C++ Developer's Toolbox - Bernhard Manfred Gruber - [https://www.youtube.com/watch?v=MNwGvqX4KH0](https://www.youtube.com/watch?v=MNwGvqX4KH0)
* C++ Committee Q&A at using std::cpp 2026 - [https://www.youtube.com/watch?v=iD5Bj7UyAQI](https://www.youtube.com/watch?v=iD5Bj7UyAQI)
* The Mathematical Mind of a C++ Programmer - Joaquín M López - [https://www.youtube.com/watch?v=9g4K-oNw1SE](https://www.youtube.com/watch?v=9g4K-oNw1SE)
* C++ Profiles: What, Why, and How - Gabriel Dos Reis - [https://www.youtube.com/watch?v=Z6Nkb1sCogI](https://www.youtube.com/watch?v=Z6Nkb1sCogI)
* Nanoseconds, Nine Nines and Structured Concurrency - Juan Alday - [https://www.youtube.com/watch?v=zyhWzoE3Y2c](https://www.youtube.com/watch?v=zyhWzoE3Y2c)
* Fantastic continuations and how to find them - Gonzalo Juarez - [https://www.youtube.com/watch?v=\_0xRMXA83z0](https://www.youtube.com/watch?v=_0xRMXA83z0)
* You 'throw'; I'll 'try' to 'catch' it - Javier López Gómez - [https://www.youtube.com/watch?v=VwloPRtTGkU](https://www.youtube.com/watch?v=VwloPRtTGkU)
* Squaring the Circle: value-oriented design in an object-oriented system -Juanpe Bolívar - [https://www.youtube.com/watch?v=DWthcNoRVew](https://www.youtube.com/watch?v=DWthcNoRVew)
* Concept-based Generic Programming - Bjarne Stroustrup - [https://www.youtube.com/watch?v=V0\_Q0H-PQYs](https://www.youtube.com/watch?v=V0_Q0H-PQYs)

https://redd.it/1sqsqb5
@r_cpp
DMA is Dead: Zero-Copy Audio via Capability-Based Shared Memory in a C++26 Microkernel

Authors: Rajeshkumar Venugopal, Third Buyer Advisory, Claude 4.6

Description: A C++26 microkernel inspired by QNX Neutrino demonstrates that DMA is unnecessary for real-time audio transfer. Four user-space processes share a single 3840-byte stereo PCM buffer through capability-based memory grants — zero memory copies, zero DMA, zero kernel-mode drivers. The producer writes interleaved 48kHz/16-bit stereo samples, grants read-only capabilities to an audio driver, a VU meter (sub-region: left channel only), and a waveform visualizer (user-space read-back). IPC transfers only a 4-byte capability ID. The driver reads PCM data directly from the producer's buffer via std::span. Revoke cascades: munmap kills all grants. IPC round-trip latency: 1.31 microseconds (Apple M3, -O2), faster than QNX Neutrino on 600MHz ARM (\~2us) and FreeRTOS context switch on Cortex-M4 (\~7us). 14 invariants formally verified by Z3 (SMT solver): 9 IPC state machine proofs + 5 capability grant proofs. No counterexample exists for any invariant. 67 Catch2 tests, 252 assertions, all passing. BSD 2-Clause licensed. No Java, no Alloy, no DMA.

Keywords: microkernel, QNX, Neutrino, C++26, zero-copy, shared memory, capability-based security, DMA-free, real-time audio, IPC, message passing, send/receive/reply, priority inversion, formal verification, Z3, SMT, F#, alloy-fsx, Catch2, resource manager, PPS, publish-subscribe, stereo PCM, RTOS, embedded systems, BSD license

License: BSD-2-Clause

Repository: https://github.com/chanakyan/qnx-micro

Related: https://github.com/chanakyan/alloy-fsx https://github.com/chanakyan/mars_pathfinder

https://redd.it/1sr5ex1
@r_cpp