TGViewer
Channel Public Channel
C++ - Reddit

C++ - Reddit

@r_cpp

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
Subscribers
230
Photos
48
Videos
8
Links
25.4K

Showing posts older than #25262 · Back to latest

Older Posts 20 shown
Post #25260 12
Building a C++ Neural Network Library from Scratch (Because I Couldn't Stand Python)

Hey everyone,



I wanted to introduce GradientCore, my open-source machine learning library written from scratch in C++.

GradientCore is my attempt at building a lightweight ML framework with a focus on performance and understanding how things work under the hood. It currently includes:

- Tensor operations with efficient memory management
- Autograd (automatic differentiation)
- Basic optimizers
- Neural network module

The project started because I personally struggle to think clearly when coding in Python. I wanted something built in C++ that I could actually understand and extend.

It began as a learning project inspired by Magicalbat’s “Coding a Machine Learning Library in C from Scratch” YouTube series. After a few failed attempts (including one very messy AI-assisted branch), I restarted clean and built it step by step.

The library is still early stage — nowhere near PyTorch level — but it’s becoming usable. All testing so far has been on my local machine, so feedback and bug reports are very welcome.


Links :-
github - https://github.com/spandan11106/GradCore-Tensor
docs - https://spandan11106.github.io/GradCore-Tensor/
blog - https://spandan11106.github.io/GradCore-Tensor/blog


I’m looking for contributors who are interested in C++ and machine learning. Even small contributions (bug fixes, documentation improvements, examples, etc.) would be greatly appreciated.

Would love to hear your thoughts or suggestions!

Thanks!

https://redd.it/1tlq21k
@r_cpp
GitHub GitHub - spandan11106/GradCore-Tensor: Machine Learning framework built from scratch in CPP. Machine Learning framework built from scratch in CPP. - spandan11106/GradCore-Tensor
Post #25259 15
14.7 | 14.7 | 0.1 | 14.7 | 15.3 | 0.6 |

\### **Latte**
| Function | Avg (cycles) | Median (cycles) | StdDev (cycles) | Min (cycles) | Max (cycles) | Δ Min-Max (cycles) |
|:-----------------|-------------:|----------------:|----------------:|-------------:|-------------:|-------------------:|
| Fast::Start+Stop | 60.1 | 60.0 | 0.1 | 59.9 | 60.4 | 0.5 |
| Mid::Start+Stop | 119.8 | 119.7 | 0.4 | 119.9 | 122.7 | 2.8 |
| Hard::Start+Stop | 148.5 | 148.4 | 0.5 | 147.9 | 150.4 | 2.5 |
| LATTE_PULSE | 29.9 | 29.8 | 0.1 | 29.7 | 30.3 | 0.6 |

\### **Chrono**
| Function | Avg (cycles) | Median (cycles) | StdDev (cycles) | Min (cycles) | Max (cycles) | Δ Min-Max (cycles) |
|:-----------------|-------------:|----------------:|----------------:|-------------:|-------------:|-------------------:|
| std::chrono::now | 153.9 | 153.4 | 0.4 | 153.1 | 156.9 | 3.3 |

https://redd.it/1tldryd
@r_cpp
Reddit From the cpp community on Reddit: Latte: a single-header latency measurement for quick insights Explore this post and more from the cpp community
Post #25258 13
Latte: a single-header latency measurement for quick insights

Hey /r/cpp, I've been working on a single-header latency measurement lib. Not meant for bottleneck detection or replacing Tracy/OpenTelemetry/perf/callgrind, but just for situations where I needed simple and trustable latency numbers during development.

\## The pitch:

* **2.5x faster per call than chrono** (RDTSC: \~60 cycles vs \~154 cycles)
* **Built-in statistics** (mean, median, stddev, skew, min, max, range, outliers)
* **Thread-safe** (per-thread ring buffers, zero contention)
* **Header-only** - nothing to do except placing monitoring beacons

\## Basic usage:

```cpp
Latte::Fast::Start(__func__);
DoWork(); // block of logic to measure
Latte::Fast::Stop(__func__);

// For loops/toroidal events:
for (;;) {
// ... work ...
LATTE_PULSE("MyLoop"); // records delta between successive calls
}

Technical implementation:

Three capture modes with different serialization guarantees:
\- Fast: __rdtsc
\- Mid: __rdtscp
\- Hard: _LFENCE+__rdtscp

Storage model:

\- Per-thread std::map<const char*, RingBuffer> (keys compared by pointer address, not string content)
\- Each ring buffer: alignas(64) for cache-line isolation, fixed 65k samples (configurable via BUFFER_PWR)
\- Zero allocations in hot path, ring buffers overwrite on wrap
\- Supports 64-deep nesting via per-thread SoA stack (stores ID, timestamp, capture mode)

Statistical cleaning:
Before computing stats, samples are bucketed (groups of 1000), bucket-max is recorded, then IQR filtering is applied to the maxima. This is more robust against long-tail outliers than raw IQR on samples.

Calibration:
When using Parameter::Calibrated, the framework measures and subtracts instrumentation overhead for each Start/Stop mode combination (e.g., Fast→Mid, Hard→Hard). Mixed-mode nesting is handled by storing the capture mode on the stack.

Example output:

| Component Samples Avg Median StdDev Min Max Range Outliers |
|--------------------------------------------------------------------------------------------|
| DoWork 10000 0.82 ms 0.81 ms 0.05 ms 0.79 ms 1.20 ms 0.41 ms 12 |
| InnerLoop 50000 0.15 ms 0.14 ms 0.02 ms 0.12 ms 0.35 ms 0.23 ms 3 |

With overhead correction enabled, it also dumps a calibration table showing measured overhead for each mode permutation.

Design decisions I’m curious about:

[0\] Pointer-as-key: Using const char* directly (string literals) as map keys to skip hashing. Feels hacky but saves cycles. Better alternatives?
[1\] Thread-local maps: Each thread owns its own std::map for ID→RingBuffer lookups. O(log N) per Stop(), but N is typically small. Considered flat_map but insertion cost for new IDs felt worse. Any thoughts ?
[2\] No RAII wrapper: Deliberately avoided RAII (Latte::Scope s("id")) to allow mixing Start/Stop modes and finer control. Trade-off worth it ?

Caveats:
\- x86_64 only (needs RDTSC/RDTSCP)
\- C++17
\- DumpToStream() not thread-safe - call only after workers stop
\- IDs must be string literals or stable static const char* (pointer comparison)

Nothing extravagant. Use case might be niche, I personally find it very useful for HFT/gamedev/tooling work where I just want to have quick insights without the measurement distorting results.

What do you think? Any obvious optimizations or design flaws I’m missing?

https://github.com/MoonFlowww/Latte

\##Bench
\### **ASM**
| Function | Avg (cycles) | Median (cycles) | StdDev (cycles) | Min (cycles) | Max (cycles) | Δ Min-Max (cycles) |
|:-----------------|-------------:|----------------:|----------------:|-------------:|-------------:|-------------------:|
| __rdtsc | 30.1 | 29.9 | 0.4 | 29.7 | 31.2 | 1.5 |
| __rdtscp | 57.7 | 57.5 | 0.9 | 57.3 | 62.6 | 5.2 |
| _LFENCE |
GitHub GitHub - fior512/Latte: Latency Telemetry with ultra low overhead Latency Telemetry with ultra low overhead. Contribute to fior512/Latte development by creating an account on GitHub.
Post #25256 17
Post #25255 13
I built a minimalist, lightweight Linux Task Manager in modern C++ (reading directly from /proc) — Looking for architecture feedback!

Hey everyone,

I wanted to dive deeper into Linux internals and system-level programming, so I built **LTM (Linux Task Manager)**. It’s a minimalist CLI tool written in C++17 that interacts directly with the kernel by parsing the `/proc` filesystem.

**Key Features:**

* **Ultra-lightweight:** Uses standard `dirent.h` for bare-metal file navigation and maximum memory efficiency.
* **Zero external dependencies:** Pure Modern C++ code.
* **Clean Architecture:** Properly structured with separated `src/` and `include/` layouts.

**What's next on the Roadmap:**

* Refactoring the file parsing logic to use `std::getline` for safer, dynamic text tokenization.
* Adding real-time CPU usage calculation per process.
* Implementing a sorting algorithm (via `std::vector`) to sort processes by highest RAM usage.
* Building a GUI frontend using `QtWidgets`.

The codebase is fully open-source, clean, and documented. I would love to get your feedback on the architecture, code quality, or any low-level optimizations you suggest!

**Check it out here:**[https://github.com/sudoRebel/linux-task-manager](https://github.com/sudoRebel/linux-task-manager)

If you like the approach, feel free to drop a ⭐ to support the project! Happy coding!

https://redd.it/1tl93xp
@r_cpp
GitHub GitHub - sudoRebel/linux-task-manager: Building a system monitoring tool from scratch to explore and manage Linux processes. Building a system monitoring tool from scratch to explore and manage Linux processes. - sudoRebel/linux-task-manager
Post #25253 13
I built a SQL-like relational database engine in C++ from scratch

Hey r/cpp,

I’ve been learning systems programming and database internals, so I started building **Ark** — a SQL-like relational database engine written entirely from scratch in C++.

Current features include:

* Handwritten tokenizer ( lexer )
* Recursive descent parser
* CRUD operations
* INNER / LEFT / RIGHT / FULL joins
* Aggregate functions
* `ALTER TABLE` support
* File persistence
* Custom diagnostics system

Everything is implemented manually:

* no parser generators
* no embedded SQL engines
* no external dependencies

One of the most challenging parts so far has been handling joins, schema evolution, and persistence consistency cleanly.

GitHub:
[https://github.com/kashyap-devansh/Ark](https://github.com/kashyap-devansh/Ark)

I’d especially appreciate feedback around architecture, parser design, query execution, or persistence design.

https://redd.it/1tkrhxq
@r_cpp
GitHub GitHub - kashyap-devansh/Ark: A lightweight SQL-like database engine written from scratch in C++, featuring a hand-written tokenizer… A lightweight SQL-like database engine written from scratch in C++, featuring a hand-written tokenizer, recursive descent parser, typed tables, full CRUD operations, and file persistence — with no ...
Post #25252 12
Low-level coding dataset

Disclaimer: this is a repost from something I put in LocalLLaMA, but with some tweaks for the r/cpp crowd - the version over there is more ML focused, this is more code focused

Hi all,

I've recently been thinking about putting together a community sourced coding dataset for finetuning models, with a heavy focus on cpp and systems programming.

My goal is to eventually have a model (say a finetune of Qwen3.6-27b) that is good at stuff like memory ownership, thread safety, optimization concepts, etc. Right now I feel like the coding knowledge of most locally runnable models is restricted to high-level langs like py and js.

Right now I'm thinking a jsonl file with categories like this:

\- generation: basic prompt/code output
\- optimization: heres slow/bloated code, make it better
\- debugging: im getting this error pls fix
\- organization: code review, interface design, restructuring, tradeoff decisions
\- tool_calling: exercises involving tool use and interpreting results

Does anyone have any ideas for things I'm missing? Curious to see what the people over here think about this kind of thing. Are there any knowledge gaps you guys feel current models have that we can maybe try to improve with this?

Thanks in advance for all the help!

https://redd.it/1tk9dgh
@r_cpp
Reddit From the cpp community on Reddit Explore this post and more from the cpp community
Post #25251 11
Why yes; Yes I will be watching this! 🙂

https://youtu.be/NXwTRzywDSk

edit: I remember playing with Cfront and then finally Borland C++ made me put Pascal aside and C++ has been my absolute favorite ever since. 😄

STL, Boost, variadic template meta-programming, MFC, been a fantastically fun time since it was always my favorite language. Don't get me wrong I love all the other grammars too. The compilers for them? C++

But no Scott Meyers?! That is surprising but then again the language has had a lot of heroes.

https://redd.it/1tk8iuy
@r_cpp
YouTube C++: The Documentary TRAILER│Out now! In 1979, Bjarne Stroustrup arrived at Bell Labs. What started as a small personal experiment became one of the world's most used, most controversial, and most powerful languages. The is the trailer for C++: The Documentary. Cast: Alexander Stepanov: Creator…
Post #25246 19
Post #25245 18
C++ profiles: a chance to fix some annoying defaults? Brainstorming and ideas.

Hello everyone,

Lately I have been thinking about the opportunity that profiles could give to C++ for "better defaults" and "cleanups".

Which profiles would you like to see in an eventually profile-enforced version as "standard" or "enabled by default" that you think can be fit reasonably?

I will start:

- ununitialized variables: must use [indeterminate]
- [nodiscard] by default? Would that be possible? Maybe this changes the meaning.
- hardened std lib guarantee?
- type safety/bounds safety (in user code)





https://redd.it/1tja9zr
@r_cpp
Reddit From the cpp community on Reddit Explore this post and more from the cpp community
Post #25244 15
FluxUI — write your C++ UI once, run on Windows, Linux, and Android natively

FluxUI — write your C++ UI once, run on Windows, Linux, and Android natively

Most C++ UI frameworks drop the ball on Android. FluxUI doesn't — same C++20 codebase, all three platforms. The framework handles all platform-specific details under the hood so you never have to think about them.

The API is Flutter-inspired (declarative widgets, reactive state), and there's a CLI to scaffold and run projects in two commands.

Just tagged v0.1.0. It's early but the core is solid.

GitHub: https://github.com/HeyItsBablu/flux

Feedback welcome — especially from anyone who's tried cross-platform C++ UI and given up.

https://redd.it/1tj6vin
@r_cpp
GitHub GitHub - HeyItsBablu/flux Contribute to HeyItsBablu/flux development by creating an account on GitHub.
Older posts →
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →