HeadlinesBriefing favicon HeadlinesBriefing.com

Why the First C++ Allocation is Always 72 KB: Unpacking the Exception Handling Mystery

Hacker News •
×

A deep dive into a curious C++ behavior reveals the first `malloc` call is consistently 72 KB. This allocation funds the 'emergency pool' for exception handling within libstdc++. When an exception is thrown, if `malloc` fails, the exception is allocated from this pool instead.

The pool's size is calculated based on the system's pointer size (8 bytes on 64-bit), object count, and overhead. Tuning via `GLIBCXX_TUNABLES` can adjust the pool size, demonstrating its configurable nature. This hidden infrastructure ensures exceptions remain throwable even during low-memory scenarios, a critical safety net for robust error handling.