Why is the first C++ (m)allocation always 72 KB?
joelsiks.com
Why is the first C++ (m)allocation always 72 KB?
1–10 of 39 posts
Re: Why is the first C++ (m)allocation always 72 KB?
#2Also, I cannot find his email address anywhere (to ask him to share it on GitHub).
Am I missing something?
Re: Why is the first C++ (m)allocation always 72 KB?
#3I would like the see the source code for libmymalloc.so, however, I don't see anything in the blog post. Nor do I see anything in his GitHub profile: https://github.com/jsikstro Also, I cannot find his email address anywhere (to ask him to share it on GitHub). Am I missing something?
Re: Why is the first C++ (m)allocation always 72 KB?
#4I would like the see the source code for libmymalloc.so, however, I don't see anything in the blog post. Nor do I see anything in his GitHub profile: https://github.com/jsikstro Also, I cannot find his email address anywhere (to ask him to share it on GitHub). Am I missing something?
https://catonmat.net/simple-ld-preload-tutorial-part-two
There's actually a better way to hook GNUs malloc:
https://www.man7.org/linux/man-pages/man3/malloc_hook.3.html
This is better because you can disable the hook inside the callback, and therefore use malloc within your malloc hook (no recursion)
But you can't use this mechanism before main()
Re: Why is the first C++ (m)allocation always 72 KB?
#5I would like the see the source code for libmymalloc.so, however, I don't see anything in the blog post. Nor do I see anything in his GitHub profile: https://github.com/jsikstro Also, I cannot find his email address anywhere (to ask him to share it on GitHub). Am I missing something?
dlsym() with the RTLD_NEXT flag basically: https://catonmat.net/simple-ld-preload-tutorial-part-two There's actually a better way to hook GNUs malloc: https://www.man7.org/linux/man-pages/man3/malloc_hook.3.html This is better because you can disable the hook inside the callback, and therefore use malloc within your malloc hook (no recursion) But you can't use this mechanism before main()
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().Re: Why is the first C++ (m)allocation always 72 KB?
#6Re: Why is the first C++ (m)allocation always 72 KB?
#7Huh. 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.
Re: Why is the first C++ (m)allocation always 72 KB?
#8Earlier quoted context omitted.
dlsym() with the RTLD_NEXT flag basically: https://catonmat.net/simple-ld-preload-tutorial-part-two There's actually a better way to hook GNUs malloc: https://www.man7.org/linux/man-pages/man3/malloc_hook.3.html This is better because you can disable the hook inside the callback, and therefore use malloc within your malloc hook (no recursion) But you can't use this mechanism before main()
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().
The global variable approach was very useful and pretty low overhead.
Re: Why is the first C++ (m)allocation always 72 KB?
#9Re: Why is the first C++ (m)allocation always 72 KB?
#10This is compiler specific and cannot be generalised as C++.