Huh. Why is this emergency pool not statically allocated? Is it possible to tune the size of this pool on libc++ startup somehow? Because otherwise it absolutely should've been statically allocated.
I did mention it briefly in the post, but you can opt-in for a fixed-size statically allocated buffer by configuring libstdc++ with --enable-libstdcxx-static-eh-pool. Also, you can opt-out of the pool entirely by configuring the number of objects in the pool to zero with the environment variable GLIBCXX_TUNABLES=glibcxx.eh_pool.obj_count=0.
Why is the first C++ (m)allocation always 72 KB?
11–20 of 39 posts
Re: Why is the first C++ (m)allocation always 72 KB?
#12This is compiler specific and cannot be generalised as C++.
Re: Why is the first C++ (m)allocation always 72 KB?
#13Re: Why is the first C++ (m)allocation always 72 KB?
#14Re: Why is the first C++ (m)allocation always 72 KB?
#15Reminds me of Perl's $^M: https://perldoc.perl.org/variables/$%5EM
In Perl you can "hand-manage" that. This line would allocate a 64K buffer for use in an emergency:
$^M = 'a' x (1 Re: Why is the first C++ (m)allocation always 72 KB?
#16Re: Why is the first C++ (m)allocation always 72 KB?
#17Earlier quoted context omitted.
The use of these hook functions is not safe in multithreaded programs, and they are now deprecated. From glibc 2.24 onwards, the __malloc_initialize_hook variable has been removed from the API, and from glibc 2.34 onwards, all the hook variables have been removed from the API. Programmers should instead preempt calls to the relevant functions by defining and exporting malloc(), free(), realloc(), and calloc().
Yeah. Shame though because it gave you the option to control exactly when you hooked and didn't hook, which let stop and start debugging allocations based on arbitrary triggers. The global variable approach was very useful and pretty low overhead.
Re: Why is the first C++ (m)allocation always 72 KB?
#18Earlier quoted context omitted.
The use of these hook functions is not safe in multithreaded programs, and they are now deprecated. From glibc 2.24 onwards, the __malloc_initialize_hook variable has been removed from the API, and from glibc 2.34 onwards, all the hook variables have been removed from the API. Programmers should instead preempt calls to the relevant functions by defining and exporting malloc(), free(), realloc(), and calloc().
Yeah. Shame though because it gave you the option to control exactly when you hooked and didn't hook, which let stop and start debugging allocations based on arbitrary triggers. The global variable approach was very useful and pretty low overhead.
Re: Why is the first C++ (m)allocation always 72 KB?
#19Earlier quoted context omitted.
Well, yes, but still quite interesting, IMHO. It's not like GCC is one of the least used compilers.
Yeah, but that isn't C++ in isolation, thus the tile is incorrect.
> EDIT (March 1, 2026): I updated the title to to clarify that this observation is specific to my environment. The original title may have implied a universal behavior, which isn’t the case. Thanks for the feedback!