Investigating C++ Memory Allocation: The 72KB Emergency Pool for Exception Handling
By
joelsiks
If you only eat one bagel today, this is the bagel.
Summary
The article investigates why the first memory allocation in C++ programs often appears to be 72KB, revealing that this is due to the C++ standard library setting up an 'emergency pool' for exception handling. The author uses debugging tools like GDB and examines source code from libstdc++, glibc, and Valgrind to trace this behavior, explaining that this pre-allocated memory ensures exceptions can still be thrown even if malloc runs out of memory during program execution.
Key quotes
· 5 pulledThe C++ standard library sets up exception handling infrastructure early on, allocating memory for an 'emergency pool' to be able to allocate memory for exceptions in case malloc ever runs out of memory.
I like to spend (some of) my time hacking and experimenting on custom memory allocation strategies and debugging memory-related issues.
Why is my first C++ (m)allocation always 72 KB?? It's the 'emergency pool' for exceptions, here's how I uncovered it using GDB and digging through the source code of libstdc++, glibc and Valgrind!
The original title may have implied a universal behavior, which isn't the case.
This observation is specific to my environment.
You might also wanna read
Technical Analysis: How Ghostty's Memory Leak Was Identified and Fixed
The article details the discovery and resolution of a significant memory leak in Ghostty, a terminal emulator. Users reported extreme memory
Debugging an Elusive emacsclient Bug: When Remote Commands Crash the Main Editor
The article describes a debugging story where the author tracked down an elusive bug in emacsclient, a utility that communicates with the ma
blog.plover.com·6mo agoDiscovery of a 64GB Memory Leak in VS Code Despite Never Using the Software
The author describes discovering a massive memory leak in VS Code that consumed 64GB of memory and had no upper limit, despite never having
Automated Software Debugging: Tools and Techniques for Finding and Fixing Bugs
This book introduces automated software debugging techniques that help locate and fix software bugs automatically. It covers recent advancem
Improving Print-Based Debugging Techniques for Developers
The article discusses the challenges of print-based debugging, particularly the issue of spammy output, and explores ways to improve this me
Spring Framework Release Train Rescheduled to June 8-14 With Critical Security Patches
The Spring development team has announced that the May release train has been rescheduled and condensed to June 8-14, 2026. Most projects wi
