Earlier quoted context omitted.
> Today the libc allocators have advanced by maybe tens of thousands of PhDs worth of theory and practice. For fun I wrote up a very basic memory manager and benchmarked it against free/malloc. On my Mac (M3) the manager was 3x faster. On a random kubernetes pod (alpine) it was 33x faster. Performance increases as memory size goes up.
If this is true, can some of your ideas be integrated into the standard libc allocator?
Stupid Smart Pointers in C
171–174 of 174 posts
Re: Stupid Smart Pointers in C
#172Or rather, given that every relevant C compiler is also a c++ compiler, just compile as c++ and use std::unique_ptr? I love C but I just can't understand the mental gymnastics of people that prefer this kind of hacks compared to just using C++
Unfortunately, that's not true. C is not 100% compatible with C++. There's a whole heap of incompatibilities that you can hit, that will prevent a lot of non-trivial C programs from compiling under C++. Things like character literals being a char in C++ and an int in C. Or C allowing designated initialisers for arrays, but C++ not.
Re: Stupid Smart Pointers in C
#173Earlier quoted context omitted.
> Use __attribute__((cleanup)). It's available in GCC and Clang Really, don’t do this, it’s a portability nightmare. If you’re going to write C stick to code that easy to run under MSVC.
Running under MSVC is overrated and more trouble than its worth. Clang and mingw-w64 GCC work just fine for targeting Windows.
mingw is radically more problematic than MSVC. Don’t use mingw.
Re: Stupid Smart Pointers in C
#174Earlier quoted context omitted.
Running under MSVC is overrated and more trouble than its worth. Clang and mingw-w64 GCC work just fine for targeting Windows.
Running under MSVC implies I'm building on Windows. In reality I'm cross compiling with Clang.