You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the compiler generates unnecessary calls to malloc, free and memset.
However, this is a private link flag and does not propagate to other targets, and there is (almost?) no malloc in this library, so this should no be a big issue.
But I'm still confused, why stop using builtin malloc, while still use the builtin free and calloc etc. (I haven't read the gcc's implementation detail, but it seems mixing user-provided malloc and builtin free is dangerous)
if you use -no-builtin-malloc flag in gcc, I believe it turns off all the __builtin_xxx functions related to malloc so there won't be a malloc matched with __builtin_free (but just free).
I think there is no issue in not giving this flag (when linking statically) -- just more neat to only use mimalloc. There might be an issue with something like realpath that allocates memory where we need to free that later (but I think it is still fine since mimalloc overrides all such calls anyway).
I don't think actual programs get slower due to lack of the optimization you point at btw. This kind of thing hardly applies in practice?
and at least they disable all builtin malloc family.
I don't think actual programs get slower due to lack of the optimization you point at btw.
I agree because this is a private compile flag in mimalloc-obj and do not propagate to other cmake targets. But a common optimize opportunity (which I have seen mutiple times) looks like this:
peopel malloc at the begining and free at end and use the pointer in the middle, but forget to remove the malloc and free when the code in the middle is refactored and the pointer is not used.
At https://github.com/microsoft/mimalloc/blob/91215a5512ed4fa916ec26349f69d44235313308/CMakeLists.txt#L392C27-L392C46 the CMake build system add
--no-builtin-malloc
flag. However, this make program runs slower.examples:
https://godbolt.org/z/xsTzj9sTb
https://godbolt.org/z/MEqoaEnqW
the compiler generates unnecessary calls to malloc, free and memset.
However, this is a private link flag and does not propagate to other targets, and there is (almost?) no malloc in this library, so this should no be a big issue.
But I'm still confused, why stop using builtin
malloc
, while still use the builtinfree
andcalloc
etc. (I haven't read the gcc's implementation detail, but it seems mixing user-provided malloc and builtin free is dangerous)The full gcc builtins can be found here:
https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
The text was updated successfully, but these errors were encountered: