5 ms·
Honestly not trying to troll, if you’re trying to avoid bloat shouldn’t you go with C instead of C++. At some point you’re going to run into virtual tables amo
by pipeline_peak 3y ago
Honestly not trying to troll, if you’re trying to avoid bloat shouldn’t you go with C instead of C++.
At some point you’re going to run into virtual tables among other overhead.
- dundarious 3y agoYour general point is in agreement with the article then.
- SubjectToChange 3y agoLess "bloat" doesn't mean more performance. C++ libraries have soundly beaten their C counterparts in HPC, HFT, ML, etc. And in any case it is still possible to write a C-dialect in C++ if you so choose.
- pipeline_peak 3y agoI was referring to bloat as in memory usage. A quick glance at Moe, I see inheritance in something as fundamental as buffers.
- SubjectToChange 3y agoAgain, you can write a C89 (even more with C++20) dialect in C++. There’s practically nothing C can do that C++ can’t. Also, the fact that the linked page recommends tinycc and pcc pretty much proves they don’t care about performance or memory usage.
- mike_hock 3y agoYou run into virtual tables more often in C because you can't build an abstraction otherwise, whereas in C++ it could be inlined. Example: Callbacks in C are always virtual, whereas in C++ you can take the callback as a template parameter. Not distinguishing between "virtual" or "function pointer" or any other names for the same concept (dynamic call address).
- pipeline_peak 3y agoC has inline, are you talking about older versions?
- pjmlp 3y agoInline is an hit, doesn't mean it gets really expanded, that is why compilers have extensions for "I really mean it, inline no matter what". C++ templates provide the mechanism to really inline complex code, run it at compile time and just place the result into the binary, instead of clunky preprocessor macros.
- mike_hock 3y agoInlining a struct of callbacks is a much more brittle optimization in C than inlining calls to member functions on a class accepted as a template argument in C++, which I consider a fair comparison because the former is the closest approximation C has for the latter. You might get a failure to inline and get direct calls to fixed function addresses in the latter case, but never virtual calls (unless the member functions themselves are virtual, of course). The former case relies on the compiler seeing through the entire call chain and being able to prove that the function pointers don't change. The idea that virtual calls can bite you in C++ but not in C is clearly nonsense, as in any situation where you'd need a virtual function in C++, you'd need a function pointer in C, and virtual functions don't happen accidentally as you have to explicitly write "virtual."
- pipeline_peak 3y ago-2 votes (im sure and counting) for an honest question, this site has really turned into something else…