Readit News logoReadit News
vitaut commented on Stdio(3) change: FILE is now opaque   undeadly.org/cgi?action=a... · Posted by u/gslin
Retr0id · a month ago
Doesn't fwrite more or less write directly to the FILE buffer, if buffering is enabled?

I'm curious to take a closer look at fmtlib/fmt, which APIs treat FILE as non-opaque?

Edit: ah, found some of the magic, I think: https://github.com/fmtlib/fmt/blob/35dcc58263d6b55419a5932bd...

I'm curious how much speedup is gained from this.

vitaut · a month ago
With fwrite that would be another level of buffering in addition to FILE's buffer. If you are interested in what {fmt} is doing, a good starting point is https://github.com/fmtlib/fmt/blob/35dcc58263d6b55419a5932bd.... It is also possible to bypass stdio completely and get even faster output (https://vitaut.net/posts/2020/optimal-file-buffer-size/) and while it is great for files, it may introduce interleaving problems with things like stdout.
vitaut commented on Stdio(3) change: FILE is now opaque   undeadly.org/cgi?action=a... · Posted by u/gslin
p0w3n3d · a month ago
However, who should really rely on internals of FILE? Isn't this a bad practice?
vitaut · a month ago
In general, it is a bad practice. However, it can be useful for some low-level libraries. For example, https://github.com/fmtlib/fmt provides a type-safe replacement for `printf` that can write directly to the FILE buffer providing comparable or better performance to native stdio.
vitaut commented on C++26: more constexpr in the core language   sandordargo.com/blog/2025... · Posted by u/jandeboevrie
jjmarr · 4 months ago
C++23 doesn't have full reflection yet. That's coming in C++26.

I've seen the vast majority of build time in a very large C++23 project be taken up by reflection in fmtlib and magic_enum because both have to use templates (I think).

vitaut · 4 months ago
{fmt} doesn't use reflection and is optimized for build speed using type erasure: https://vitaut.net/posts/2024/faster-cpp-compile-times/

u/vitaut

KarmaCake day871May 12, 2014
About
Carbon-based open sourcerer, code necromancer and a former alien. Author of C++20 std::format and http://github.com/fmtlib/fmt. Opinions are not mine.
View Original