All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Investigating C++ Memory Allocation: The 72KB Emergency Pool for Exception Handling

By

joelsiks

3mo ago· 7 min readenInsight

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 pulled
The 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.
Snippet from the RSS feed
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!

You might also wanna read