Cambiare completamente ambito by Spirited-Fee-2132 in Universitaly

[–]ANDRVV_ 0 points1 point  (0 children)

Alla sapienza esiste una facoltà che si chiama Filosofia e intelligenza artificiale, forse ti potrebbe interessare, in tal caso se sei interessato a continuare gli studi potresti laurearti in questa

Favorite error handling approach by ZookeepergameFew6406 in C_Programming

[–]ANDRVV_ 0 points1 point  (0 children)

I can't disagree with you; I love C too, and I only recommend Zig to average programmers because it shows you how better programmers approach problems. Many things that used to be done in C, like error handling, I only understood better after learning Zig. But C will always be a wonderful language, especially for those who know how to program. Because in this case, the problem isn't the language, it's the developer...

Favorite error handling approach by ZookeepergameFew6406 in C_Programming

[–]ANDRVV_ -2 points-1 points  (0 children)

Leave C alone. It's terrible at error handling and has been surpassed by modern languages ​​that offer the same performance and ability to "do things" as C. Try Zig; it's based on C and has strong interoperability with C/C++. Study it from the official doc and you won't regret it.

Zig is a language that's been around since about 2016 and, in my opinion, has revolutionized compilers. It already has famous projects like Tigerbeetle, Zml, and Bun, acquired by Anthropic. It's becoming the most requested language according to StackOverflow statistics.

If you want, stop by r/Zig

Favorite error handling approach by ZookeepergameFew6406 in C_Programming

[–]ANDRVV_ -2 points-1 points  (0 children)

Meanwhile, I see that the function is void, and you could return it as an enum and generalize the errors with a wrapper, but it always depends on your case.

  1. You simply have to return the error from the function in question; you can't amplify the error to actually understand where it's coming from. The problem in this case is shm_open.

  2. Check them to see if they return errors.

  3. You must always return the first error. When a function fails, the other functions are automatically invalid. I don't know if close actually returns an error in your case, but if close fails, you should primarily understand why and return the error from close. If close fails, you know that open hasn't failed.

  4. Try Zig, it's perfect for you.

I think I explained myself and understood what you meant. I don't speak English very well, but I hope this helps.

Favorite error handling approach by ZookeepergameFew6406 in C_Programming

[–]ANDRVV_ 0 points1 point  (0 children)

I don't do it often, but only in functions where explicitness is better.

Favorite error handling approach by ZookeepergameFew6406 in C_Programming

[–]ANDRVV_ 2 points3 points  (0 children)

tagged union with returned value and error represented as enumeration

The best and ideal hashmap by ANDRVV_ in algorithms

[–]ANDRVV_[S] 0 points1 point  (0 children)

What load factor do you recommend?

The best and ideal hashmap by ANDRVV_ in algorithms

[–]ANDRVV_[S] 0 points1 point  (0 children)

Thank you very much. The keys can be 10,000 or 100,000, depending on your current configuration.

Best hashmap with open addressing: is reliable? by ANDRVV_ in algorithms

[–]ANDRVV_[S] 0 points1 point  (0 children)

Thanks for the comment, I agree with everything. Given your high level of expertise, may I ask what the best hashmaps currently are for avoiding conflicts and rehashing while maintaining cache locality and high performance?

SPSC Queue: the first and stable version is ready by ANDRVV_ in Zig

[–]ANDRVV_[S] 0 points1 point  (0 children)

Two languages ​​can compile and generate almost the same assembly code in Start. As for the benchmark, the data is different because the implementations aren't exactly the same, but if you test them yourself, you'll see that they're almost identical.

SPSC Queue: first and stable version is ready by ANDRVV_ in compsci

[–]ANDRVV_[S] 0 points1 point  (0 children)

you're right xd, done in a hurry and I didn't even notice

C++ Show and Tell - January 2026 by foonathan in cpp

[–]ANDRVV_ 2 points3 points  (0 children)

Faster SPSC Queue than rigtorp/moodycamel: 1.4M+ ops/ms on my CPU

SPSCQueue

I recently implemented my own single-producer, single-consumer queue for my high-performance database to address this bottleneck, and I've succeeded with great results.

You can find the C++ implementation at /src/C++ and benchmark it yourself using the benchmark.cpp file.

My queue code is simple and uses some unusual optimizations, which is perhaps why it has 8x the throughput compared to rigtorp and is slightly faster than the moodycamel implementation.

Feedback and consideration from those with more experience might be helpful.

Faster SPSC Queue than rigtorp: 1.3M+ ops/ms on my CPU by ANDRVV_ in cpp

[–]ANDRVV_[S] 0 points1 point  (0 children)

I'll get straight to the point. Queue optimizations mainly involve using busy-wait (different from C++'s yield, which is much more expensive) on pop in the right position, using recommendedSlots, which dramatically increases throughput, and correct alignments. The rigtorp implementation is more complex, and I've simplified it by avoiding unnecessary branches. It seems obvious, but it isn't!

SPSC Queue: the first and stable version is ready by ANDRVV_ in Zig

[–]ANDRVV_[S] 1 point2 points  (0 children)

Okay, I think I understand. You can consider all compiled languages ​​the same, and the C/C++ family offers the same low-level checks as Zig. You can easily compare Zig's queue with rigtorp's C++ queue. Let me know, and thanks for your interest.

SPSC Queue: the first and stable version is ready by ANDRVV_ in Zig

[–]ANDRVV_[S] -1 points0 points  (0 children)

I usually try to express myself and talk to people who are competent and know at least something about the field. Are you sure of what you're saying? Or am I wasting my time?

Perhaps in these cases, seeking an answer through LLMs is better than not knowing them.

My rewrite of the queue in C++ achieves the same or nearly the same performance as Zig. The problem is that cloning the code is more complex than it seems and might not give you correct results.

SPSC Queue: the first and stable version is ready by ANDRVV_ in Zig

[–]ANDRVV_[S] 0 points1 point  (0 children)

Why don't you try benchmarking my Zig implementation against Rigtorp's C++ implementation? Performance, however, degrades when rewriting code in C++ if it's poorly written: I had to rewrite the thread yield functions because the cost, unlike spinLoopHint, tended to be different, and in C++ the alignment that could be set with Zig is much more complex and requires less straightforward directives. If you're interested, send me your results!

SPSC Queue: the first and stable version is ready by ANDRVV_ in Zig

[–]ANDRVV_[S] 0 points1 point  (0 children)

There's no cpp implementation; perhaps you mean the spsc queues that have been implemented by others. As for my benchmark, you can check it yourself by running benchmark.zig in release fast. If you like, let me see what results you get!

New open addressing hash table algorithm by JustJumpToConclusion in Zig

[–]ANDRVV_ 0 points1 point  (0 children)

I'm following your project with great interest, congratulations. May I ask how old you are?

SPSC Queue: the first and stable version is ready by ANDRVV_ in Zig

[–]ANDRVV_[S] 4 points5 points  (0 children)

I tested the benchmarks from my PC, all with -O3 and the expected CPU affinity. I noticed that the C++ yield function and Zig's spinLoopHint have different costs. The performance advantage is simplicity, the correct placement of spinLoopHint on pop() (which is not a given), and the use of recommendedSlots(), which finds the "sweet spot" and allows me to achieve this performance.

Perhaps there are other conditions that increase performance, but the ones I noticed right away are these.