Re:Honey, I shrunk {fmt}: bringing binary size to 14k and di...
by kllrnohj on Sunday September 01, 2024 @02:01PM
(#41418878)
Yes they could have just defined their own global operator new/delete to have a micro-runtime. Same as you'd do if you were doing a kernel in C++. Super easy, barely an inconvenience
Re:Honey, I shrunk {fmt}: bringing binary size to 14k and di...
by vitaut on Sunday September 01, 2024 @11:01PM
(#41422269)
Changing global new/delete is a non-starter in a reusable library. Allocator is a much more localized change and roughly the same amount of work.
Re:Honey, I shrunk {fmt}: bringing binary size to 14k and di...
by gobblegobble2 on Sunday September 01, 2024 @02:16PM
(#41418978)
> Notably I thought the issue would be the throwing of `std::bad_alloc`, but the new version still implements std::allocator, and throws bad_alloc.
The new version uses `FMT_THROW` macro instead of a bare throw. The article says "One obvious problem is exceptions and those can be disabled via FMT_THROW, e.g. by defining it to abort". If you check the `g++` invocation, that's exactly what the author does.
Notably I thought the issue would be the throwing of `std::bad_alloc`, but the new version still implements std::allocator, and throws bad_alloc.
And so I assume the issue is that the global `operator new` is concrete (it just takes the size of the allocation), thus you need to link to the C++ runtime just to get that function? In which case you might be able to get the same gains by redefining the global `operator new` and `operator delete`, without touching the allocator.
Alternatively, you might be able to statically link the C++ runtime and have DCE take care of the rest.