es
Feedback
C++ - Reddit

C++ - Reddit

Ir al canal en Telegram

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

Mostrar más
228
Suscriptores
Sin datos24 horas
Sin datos7 días
+630 días
Archivo de publicaciones
Rad-UI released! A new reactive, cross-platform C++20 UI framework https://github.com/just-language/Rad-UI https://redd.it/1tyrjgo @r_cpp

"Criticism of C++" wikipedia page deleted? While adding information related to C++ to the Vietnamese wikipedia, I found that the "Criticism of C++" wikipedia page has been deleted. Why such an important page can be deleted? https://redd.it/1tyjig5 @r_cpp

How I made my SPSC queue faster than rigtorp/moodycamel's implementation https://github.com/ANDRVV/SPSCQueue https://redd.it/1tyestl @r_cpp

The Story of C++: The World's Most Consequential Programming Language | The Official Story https://youtu.be/lI7tMxzSJ7w?si=5hS9qJjQKL_9m_yr https://redd.it/1txhe5n @r_cpp

PSA - Do not assign the result of ::getenv to a std::string This is a lesson I apparently have to learn repeatedly. Many, many times. Way too many times. Unit tests are failing, I'm too ADD to actually read the error message for comprehension, fart around changing things to try to find why the exception is being thrown, then spontaneously remember "oh, yeah, ::getenv will return NULL if the variable hasn't been defined, and assigning a NULL to a std::string is Bad Juju. Wasted a whole day on this nonsense. I know this. I have known this for years, and I still make this mistake. Blah. Needed to vent. https://redd.it/1tx3eb6 @r_cpp

Rotation revisited: A shocking discovery about gcc’s unidirectional rotation algorithm https://devblogs.microsoft.com/oldnewthing/20260603-00/?p=112378 https://redd.it/1twtfv8 @r_cpp

I spent a month optimizing my epoll based HTTP server from 15k req/sec to 125k req/sec Greetings to my fellow nerds. A month ago, I had zero network programming experience. So I decided to fix that by building an epoll based HTTP server from scratch and benchmarked every major architectural change along the way. # Performance Benchmarks : * **Benchmark command** : `wrk -t4 -c10000 -d10s http://127.0.0.1:8080/` * **Request**: `GET /index.html` * **Response**: Static HTML file (\~1500 bytes) * **CPU**: Intel i5-13420H (13th Gen) * **Compiler**: Clang (O3) |Architecture|Throughput (req/sec)|Description| |:-|:-|:-| |**Blocking**|\~15k|Single threaded blocking accept/read/write| |**Epoll (LT)**|\~34k|Single threaded event loop utilizing non blocking I/O multiplexing| |**Epoll (LT, keep alive)**|\~37.5k|Single threaded event loop with persistent connections| |**Epoll (LT, keep alive, sendfile)**|\~41k|Single threaded event loop with persistent connections and zero copy file serving| |**Epoll (LT, keep alive, sendfile, multithreading)**|\~125k|Multithreaded architecture running 4 concurrent epoll loops (optimal on test machine)| # Some Surprising Observations : * sendfile mattered less than I expected... for a server whose entire purpose is to serve files, I was expecting a bigger gain but maybe because my file was only \~1.5KB, it did not help much. * More threads made things worse : |Worker Threads|Throughput (req/sec)| |:-|:-| |1|\~40k| |2|\~95k| |3|\~115k| |4|\~125k| |5|\~90k| |6|\~90k| |8|\~75k| |10|\~70k| |12|\~65k| My CPU has 6 physical cores and 12 logical processors, I suspect that the cost of all the syscalls for every loop, context switching, and lock contention on shared kernel objects, dominated on higher thread counts. Though I havent fully investigated it yet. # Profiling with perf : |Function|Approx. CPU Samples| |:-|:-| |readSock()|\~22%| |writeSock()|\~16%| |parse()|\~8%| |std::format()|\~7%| |open()|\~3%| |sendfile()|\~2.5%| Turns out Im still spending more time reading and parsing requests than sending responses, meaning there might still be room for batched reads or buffer pooling in a future iteration... # Final Thoughts : I could hunt for possible micro optimizations or even experiment with an edge triggered architecture but im kinda burnt out at this point and this feels like a great point to end this project... The codebase is pretty small (\~1k LOC), so if anyone's interested in taking a look : [https://github.com/Raju1173/epoll-http-server](https://github.com/Raju1173/epoll-http-server) https://redd.it/1twh4e1 @r_cpp

2026 Cppcon Hi everyone, I received the HRT Cppcon scholarship, and I'm excited to attend the conference and to those who attended as students, I'm curious about your experience! Is it a good opportunity to also network as well? I would love to get a job as a C++ developer in the near future. https://redd.it/1tw7pdb @r_cpp

consteig. How much math can you force the compiler to do at compile time? (a lot) [consteig src](https://github.com/MitchellThompkins/consteig) [consteig docs](https://mitchellthompkins.github.io/consteig/) Presented here is a header-only C++ compile-time eigenvalue and eigenvector solver with no dependencies beyond a C++17 compatible compiler (so no stdlib dependency, no .cpp files). I started on this project 6 years ago and only got back into finishing it recently. Technically this is a "personal project" I suppose but I intend it to be used by other C++ programmers (or math nerds) and I'd consider it "production-quality". So I think a formal post is acceptable. If you don’t remember (or haven’t encountered) eigenvalues/vectors, eigenvectors are vectors whose directions are unchanged when linear transforms are applied to the system (which makes them special). Eigenvalues are the factors by which an eigenvector is stretched or shrunk (but whose direction remains unchanged); usually this is expressed as matrices in linear algebra. They’re useful for lots of engineering problems. For a certain class of problems the matrix for which you want to find the eigenvalues/vectors doesn’t change, effectively making the eigenvalues/vectors constants. These are things like state space matrices for LTI systems, roots of a polynomial, structural dynamics, and some graph/network problems. I’ve got some [examples in my docs](https://mitchellthompkins.github.io/consteig/examples/dc-motor/). If you need the eigenvalues/vectors for those in a C++ program, what you do today is either (1) calculate them at run-time using something like Eigen or (2) calculate them in matlab/python and hard-code them into your program. I’ve pushed all of the math for doing that into compile-time using the compiler itself. This means you can define static matrices at compile time, and save the eigenvalues/vectors off as constants in memory without needing to spend any run-time cycles nor to independently track/calculate them with another tool. Again; I’ve got examples above, but you can use this to do something like specify filter characteristics (sample rate, cut-off frequency, Order, etc...) and at compile time calculate all the digital filter coefficients. So you can end up doing something like: // 3rd order butterworth with 100Hz cut-off and 1kHz sample rate static constexpr constfilt::Butterworth<double, 3> b(100.0, 1000.0); //Call at 1kHz at run-time b.filt(new_sample); And you never need to use python nor matlab to figure out what those coefficients are. I’ve also got another less-polished / less-tested / less-complete compile-time library called [constfilt](https://github.com/MitchellThompkins/constfilt) now that does exactly that. consteig available on GitHub and in vcpkg; I’m working on Conan :). https://redd.it/1tw8dpc @r_cpp

proof of concept c++ runtime & standard library https://github.com/antsif-a/platinum https://redd.it/1tw6v6h @r_cpp

Is it possible to force compiler stack allocation? int main() { foo(); // static // creates two variables, one const and one mutable, // then prints the section of memory they end up in, // followed by printing the section name itself. poo(); // automatic // does the same thing with a normal local variable // and prints its section name. // we also import a disassembler so we can inspect // how this actually affects the generated code. // inspector function bytes function address deref jump count inspectfunction(GrabFunctionBytes(foo), reinterpretcast<uintptrt>(&foo), 1); inspectfunction(GrabFunctionBytes(poo), reinterpretcast<uintptrt>(&poo), 1); } foo output: (statics) const: .rdata (0x7ff63ff03188) mutable: .data (0x7ff63ff1c008) snippet #1 0x7FF63FE7CBB0 | 48 8D 05 51 F4 09 | lea rax, rip+0x9F451 abs: 0x7FF63FF1C008 <-- 0x7FF63FE7CBB7 | 48 89 45 08 | mov rbp+0x08, rax 0x7FF63FE7CBBB | 48 8D 05 C6 65 08 | lea rax, rip+0x865C6 abs: 0x7FF63FF03188 <-- 0x7FF63FE7CBC2 | 48 89 45 28 | mov rbp+0x28, rax 0x7FF63FE7CBC6 | 8B 05 BC 65 08 00 | mov eax, rip+0x865BC abs: 0x7FF63FF03188 <-- poo output: (automatic) integer: stack / heap (0xbc06ff454) snippet #2 0x7FF63FE8B98C | E8 4E 79 FC FF | call -0x386AD 0x7FF63FE8B991 | 90 | nop 0x7FF63FE8B992 | C7 45 04 33 03 00 | mov dword ptr rbp+0x04, 0x333 <-- 0x7FF63FE8B999 | 48 8D 45 04 | lea rax, rbp+0x04 <-- 0x7FF63FE8B99D | 48 89 45 28 | mov rbp+0x28, rax What I'm trying to achieve is getting the compiler to prefer stack-based dereferencing over RIP-relative dereferencing not counting branching/jumps and calls ofc. I know I can control this to some extent by just avoiding static, but it starts getting annoying with things like std::cout and other CRT objects since they naturally end up in sections like .data.rdata, and .bss. I've tried a few different methods already. Some worked partly, some didn't really solve the issue. I'm mainly just wondering if there's a cleaner way to push things toward runtime (stack/heap) storage and avoid these RIP-relative accesses, without having to rely on weird hacks or patching the compiler itself. https://redd.it/1tw3d10 @r_cpp

I compiled TradingView’s PineScript to native C++ for backtesting — 104× faster than the Python tools, deterministic, bit-for-bit parity with TradingView (231/232) PineScript is the de-facto language retail traders use to write trading strategies — but it only runs inside TradingView’s closed sandbox. You can’t run it locally, can’t run it at scale, and can’t independently verify the backtest it shows you. I spent \~5 months building a transpiler (Pine v6 → C++) plus a native runtime to fix that. It’s open source. A few problems that were fun to solve, and where I’d genuinely like scrutiny: Determinism. To match a reference implementation trade-for-trade, the same input has to produce a byte-identical trade list every run — so floating-point operation order is fixed and reproducible across runs. No -ffast-math reordering surprises. Matching a spec I can’t see (clean-room). TradingView’s broker emulator — fill ordering, margin handling, bar-magnifier intrabar logic — isn’t documented. I implemented from the public Pine grammar, then reverse-engineered the emulator’s behavior by hand-exporting its “List of Trades” and diffing against my output across \~312K trades / 232 strategies spanning 22 feature categories (TA, brackets, OCA, MTF/LTF, matrices, UDTs, sessions…). 231/232 match exactly. The one outlier is TradingView’s own non-determinism at a 1× equity-margin boundary — mine is deterministic and, I’d argue, the correct one (documented in the repo). Performance. Median backtest 9.7 ms vs 1,070 ms for PyneCore (Python, GIL + IPC overhead) → \~104×; \~6.7× vs vectorbt (Numba). \~17M bars/sec. A big chunk of the optimization-workflow win is dlopen + run, so sweeping parameters doesn’t recompile. Benchmark honesty: “104×” is median single-backtest vs PyneCore; full methodology + run_corpus.sh to reproduce all 232 probes is in the repo. Engine is Apache-2.0, corpus is public, transpiler source is available. Background: solo, came from a CFD / numerical-computing background, which is where the determinism + perf obsession comes from. Repo: https://github.com/pineforge-4pass/pineforge-engine Happy to get torn apart on the numerical approach or the benchmark setup — that’s why I’m posting. https://redd.it/1tw1lno @r_cpp

Dsa C++ Where I should learn dsa in c++ where all the topics are covered....from basics to advanced in india https://redd.it/1tw0dp0 @r_cpp

speech-core — C++17 on-device voice-agent runtime (VAD + STT + diarization + TTS), dual ONNX / LiteRT backends, Apache 2.0 Open-sourcing a C++17 runtime I've been using for real-time voice agents. The orchestration core is pure C++17 with zero ML dependencies (state machine, VAD-driven turn detection, interruption handling, speech queue with cancel/resume, audio utilities — ring buffer, resampler, mel/STFT). Models sit behind small abstract interfaces (STTInterface, TTSInterface, VADInterface, etc.) so consumers can bring their own backend. Two reference backends, each independently buildable via a CMake option: - SPEECHCOREWITHONNX → ONNX Runtime (Silero VAD, Parakeet STT, Kokoro TTS, DeepFilterNet3) - SPEECHCOREWITHLITERT → LiteRT — libLiteRt from Google's ai-edge-litert PyPI wheel (Silero VAD, Parakeet STT, Nemotron streaming STT, Omnilingual STT, Pyannote diarization, WeSpeaker embeddings, VoxCPM2 TTS) Both CPU today; an optional CUDA / TensorRT execution provider just landed on the ONNX path (SPEECHCOREWITHCUDA, gated, default off, with build-flag + env (SPEECHCOREORTPROVIDER) + runtime-probe resolution and silent CPU fallback). Platforms: Linux x8664 + aarch64, Windows x8664, Android. A stable C ABI (speechcorec.h) makes it trivially bindable from Swift / Kotlin / Python — speech-swift is a sibling project that consumes it through a prebuilt XCFramework binary target. Apache 2.0. Tested on macOS / Linux / Windows in CI; LiteRT runtime is fetched per-platform from the official wheel by a small shell script. Repo: https://github.com/soniqo/speech-core Feedback on the interface design / build setup very welcome. https://redd.it/1tvuifx @r_cpp

C++ Performance Quiz - A small side project to test your intuition for slow code https://quiz.cpp-perf.com/ https://redd.it/1tvnwc0 @r_cpp