ar
Feedback
C++ - Reddit

C++ - Reddit

الذهاب إلى القناة على 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

إظهار المزيد
228
المشتركون
لا توجد بيانات24 ساعات
+17 أيام
+230 أيام
أرشيف المشاركات
studyplan.dev has been completely redesigned I noticed that the creator of https://www.studyplan.dev/ completely redesigned the website. It used to have a bunch of random AI generated pictures on every page, now the website looks really neat. https://redd.it/1lrmc10 @r_cpp

How long to master c++ from Python or other languages Hello everyone. I am in transition to going dive into C++, how long it normally takes to master it specially from other languages. also, how to get jobs in C++ developer to improve the skillset. https://redd.it/1lrkwwh @r_cpp

cpp.libhunt.net and articles How to pass moderation of an article on cpp.libhunt.net? Have you published your development articles there? https://redd.it/1lrhyd1 @r_cpp

I wrote a tool to stop make -j from OOM-killing my C++ builds Hey everyone, Like many of you, I often work on large C++ codebases where running make -j with full parallelism is essential to keep build times manageable. I have a build VM with 32 cores but only 16GB of RAM. When I'd kick off a build, it was a lottery whether it would finish or if the system would spawn too many g++/clang++ processes at once, exhaust all the memory, and have the OOM killer nuke a random compiler job, failing the entire build. The usual workaround is to manually lower the job count (make -j8), but that feels like leaving performance on the table. So, I wrote a simple C-based tool to solve this. It's called Memstop, a tiny LD_PRELOAD library. It works as a gatekeeper for your build: 1. Before make launches a new compiler process, Memstop intercepts the call. 2. It checks the system's available memory in /proc/meminfo. 3. If the available memory is below a configurable threshold (default 10%), it simply waits until another job finishes and memory is freed. This throttles the build based on actual memory pressure, not just a fixed job count. The result is that you can run make -j$(nproc) with confidence. The build might pause for a moment if memory gets tight, but it won't crash. Using it is straightforward: # Require 20% available memory before spawning a new compiler process export MEMSTOPPERCENT=20 LDPRELOAD=/path/to/memstop.so make -j I'm sharing it here because I figured other C++ devs who wrestle with large, parallel builds might find it useful. It's a single C file with a Makefile and no complex dependencies. The code is on GitHub (GPLv3). I would love to hear your thoughts\! Link: https://github.com/surban/memstop https://redd.it/1lrg764 @r_cpp

Florent Castelli: A note about safety - (Fixed version) https://youtu.be/VAnlVjrDouA https://redd.it/1lrczxn @r_cpp

Desktop app development in cpp Hello, I have experienced deskrop app development using qt in 2017 and right now im lost. since 2018 ive been changing my path into android java and nodejs development. but right now i want to start over develop desktop (mainly windows) apps using cpp or rust and i want to learn again. i just dont kbow at all which path should i choose, i dont even follow cpp versions. please advice me on how can i develop windows apps thank you https://redd.it/1lra8ab @r_cpp

Martin Fowler vs Uncle Bob – What's the Right Function Length? https://youtu.be/hPPFri2zRfw?si=PugMR9aB9LHot2UD https://redd.it/1lr2e8r @r_cpp

Flortent Castelli: A note about safety https://youtu.be/LuCfYMg5btI https://redd.it/1lqxxzm @r_cpp

Library Hardware performance monitoring directly in your C++ code Hey r/cpp! I'm back with an update on my library that I posted about a year ago. Since then, perf-cpp has grown quite a bit with new features and users, so I thought it's time to share the progress. What is perf-cpp? It's a C++ library that wraps builds on the perf subsystem, letting you monitor hardware performance counters and record samples directly from your application code. Think perf stat and perf record, but embedded in your program with a clean C++ interface. Why would you want this? Tools like perf, VTune, and uProf are great for profiling entire programs, but sometimes you need surgical precision. Maybe you want to: - Profile just a specific algorithm or hot loop - Compare performance metrics between different code paths - Build adaptive systems that tune themselves based on hardware events - Link memory access samples with knowledge from the application, e.g., data structure addresses - Generate flamegraphs for a specific code paths The library is LGPL-3.0 licensed and requires Linux kernel 4.0+. Full docs and examples are in the repo: https://github.com/jmuehlig/perf-cpp I'm genuinely curious what the community thinks. Is this useful? How could it be better? Fire away with questions, suggestions, or roasts of my code! https://redd.it/1lqzaxm @r_cpp

wait free programs parallelism clarification in parallelism you have wait free, and lock free programs … lock free can be done easily by just using compare and exchange with spin locks … so if each spin lock is on its own pinnned core so no thread context switching cost occurs … does that mean this program is “wait free”? for those curious see this https://stackoverflow.com/questions/4211180/examples-illustration-of-wait-free-and-lock-free-algorithms https://redd.it/1lqy2ks @r_cpp

Audio Plugin Conventions Hi all, am creating an audio plugin using the VST SDK. But the query applies to other frameworks also. Basically, the way these plugins work leads me down some strange coding ways, for example extremely long switch statements (50+ cases) for parameter handling, classes with 100 getters and setters. I was wondering how others handle these strange parts that are simple but become cumbersome purely through amount-of-text. https://redd.it/1lqw8so @r_cpp

Non-blocking asynchronous timeout I understand std::future has blocking waitfor and waituntil APIs but is there a way to achieve timeout functionality without blocking? Thank you! https://redd.it/1lqvddk @r_cpp

Cpp and DSA from scratch in 6 months Hi, Can anyone recommend good resources for learning C++ and Data Structures & Algorithms (DSA) from scratch? https://redd.it/1lqq3cc @r_cpp

Learning and practicing cpp Hi everyone, I am about to start my journey learning cpp and I need your help . I saw that everybody here recommend learncpp.com but I wonder where should I practice, I have prior knowledge to programming but I want to build strong foundations for my career . Please recommend me resources for learning and practice https://redd.it/1lqmvxj @r_cpp

BlueSky # Is there an active community of C++ programmers on BlyeSky? Do you use this social network? https://redd.it/1lqjhnb @r_cpp

Looking for C++ projects for portfolio Hi. I’ve been working as a software engineer for 5 years now. I know the ins and outs of web and mobile development with React, Nextjs and React Native. However, I’ve actually had a dream of working for Supercell for quite some time. 99% of their engineering positions require extensive knowledge of C++. It’s probably a difficult switch to the gaming industry, but I’m looking for a few semi small projects to kind of get the feel for C++ and common tools used in that industry. What do i need to learn to make the switch (terms and tools), and what projects would help me get there? Any common games people make for example? https://redd.it/1lqhjoi @r_cpp

(areaSq >= areaRect && i < squares.size()) {                 top5.pushback(std::makeunique<VSquare>(squaresi++));             } else if (j < rectangles.size()) {                 top5.pushback(std::makeunique<VRectangle>(rectanglesj++));             }         }         benchmark::DoNotOptimize(top5);     } } BENCHMARK(BMVirtualFunction)->Arg(1000)->Arg(10000)->Arg(100000)->Arg(1000000)->Arg(10000000); // -------------------- Benchmark:rust dyn trait like -------------------- static void BMRustDynTraitLike(benchmark::State& state) {     sizet count = state.range(0);     std::vector<Square> squares;     std::vector<Rectangle> rectangles;     for (auto : state) {         generateShapes(squares, rectangles, count);         std::sort(squares.begin(), squares.end(), (auto a, auto b){             return a.area() > b.area();         });         std::sort(rectangles.begin(), rectangles.end(), (auto a, auto b){             return a.area() > b.area();         });         std::vector<ShapeView> top5;         sizet i = 0, j = 0;         while (top5.size() < 5 && (i < squares.size() || j < rectangles.size())) {             double areaSq = (i < squares.size()) ? squares[i].area() : -1;             double areaRect = (j < rectangles.size()) ? rectangles[j].area() : -1;             if (areaSq >= areaRect && i < squares.size()) {                 top5.pushback(ShapeView{ &squarevtable, new Square(squares[i++]) });             } else if (j < rectangles.size()) {                 top5.pushback(ShapeView{ &rectvtable, new Rectangle(rectangles[j++]) });             }         }         benchmark::DoNotOptimize(top5);     } } BENCHMARK(BMRustDynTraitLike)->Arg(1000)->Arg(10000)->Arg(100000)->Arg(1000000)->Arg(10000000); https://redd.it/1lqey0u @r_cpp

why c++ is slower than rust Quick C++ Benchmarks #include <benchmark/benchmark.h> #include <vector> #include <algorithm> #include <random> #include <memory> // -------------------- virtual function -------------------- struct Shape {     virtual double area() const = 0;     virtual ~Shape() = default; }; struct VSquare : public Shape {     double side;     VSquare(double s) : side(s) {}     double area() const override { return side side; } }; struct VRectangle : public Shape {     double width, height;     VRectangle(double w, double h) : width(w), height(h) {}     double area() const override { return width height; } }; // -------------------- function table -------------------- struct ShapeVTable {     double (area)(const void);     void (destroy)(void); }; struct ShapeView {     const ShapeVTable vtable;     void object;     ShapeView(const ShapeVTable _vtable, void object)         : vtable(vtable), object(object) {}     ShapeView(ShapeView&& other) noexcept         : vtable(other.vtable), object(other.object) {         other.object = nullptr;     }     ~ShapeView() {         if (object) vtable->destroy(object);     }     double area() const {         return vtable->area(object);     } }; void generateVShapes(std::vector<VSquare>& squares, std::vector<VRectangle>& rectangles, sizet count) {     std::mt19937 rng(42);     std::uniformrealdistribution<> dist(1.0, 100.0);     squares.clear();     rectangles.clear();     for (sizet i = 0; i < count / 2; ++i) {         squares.emplaceback(dist(rng));         rectangles.emplaceback(dist(rng), dist(rng));     } } struct Square {     double side;     double area() const { return side * side; } }; struct Rectangle {     double width, height;     double area() const { return width * height; } }; double squarearea(const void obj) {     return static_cast<const Square>(obj)->area(); } void squaredestroy(void* obj) {     delete staticcast<Square>(obj); } const static ShapeVTable square_vtable = { square_area, square_destroy }; double rect_area(const void obj) {     return staticcast<const Rectangle*>(obj)->area(); } void rectdestroy(void obj) {     delete static_cast<Rectangle>(obj); } const static ShapeVTable rectvtable = { rectarea, rectdestroy }; void generateShapes(std::vector<Square>& squares, std::vector<Rectangle>& rectangles, sizet count) {     std::mt19937 rng(42);     std::uniformrealdistribution<> dist(1.0, 100.0);     squares.clear();     rectangles.clear();     for (sizet i = 0; i < count / 2; ++i) {         squares.emplaceback(dist(rng));         rectangles.emplaceback(dist(rng), dist(rng));     } } // -------------------- Benchmark:虚函数 -------------------- static void BMVirtualFunction(benchmark::State& state) {     sizet count = state.range(0);     std::vector<VSquare> squares;     std::vector<VRectangle> rectangles;     for (auto : state) {         generateVShapes(squares, rectangles, count);         std::sort(squares.begin(), squares.end(), (auto a, auto b) {             return a.area() > b.area();         });         std::sort(rectangles.begin(), rectangles.end(), (auto a, auto b) {             return a.area() > b.area();         });         std::vector<std::uniqueptr<Shape>> top5;         sizet i = 0, j = 0;         while (top5.size() < 5 && (i < squares.size() || j < rectangles.size())) {             double areaSq = (i < squares.size()) ? squaresi.area() : -1;             double areaRect = (j < rectangles.size()) ? rectanglesj.area() : -1;             if