'Replacing malloc() with my own implementation
I need a fast malloc() / free() replacement. There's mimalloc vom Microsoft Research which is actually on average the fastest malloc()- / free()-replacement. I've read the paper and the design is simple and straightforward. But mimalloc has an addition to speed up allocations and delalocations for languages with rerference-countet object-graphs which needs some extra space (not relevant) and some more CPU-time (relevant). So I think it would be manageable to implement my own memory-allocator basing on mimalloc within some days for Windows and Linux.
Actually I would rather need a replacement for a C++20 allocator<>-compliant class. But I've a lot of function<>-objects which themselfes manage external objects where my bind<>-objects are copied into. And C++ dropped the support for allocators with function-objects for reasons I don't understand. I've thought it would be easy to replicate the code for a function<>-object in my own class but I found no way to extract the function signatures parameters given in the signature template parameter to the calling-operator of my function-object. I had a look into the sourcecode of my MSVC 2019 C++ headers and I found that this is done with some internal _*-facilities of the compiler. So I've got to stick with C++'s own function-objects without configurable memory-allocation.
It's not mandated by the C++-standard but actually all std::allocator<>-implementations use malloc() / free() internally (partitially to make memory-allocation replaceable in a way I'd like to do) so it would be a practical solution to remplace malloc() / free() itself.
Under most Unices it's quite easy to replace malloc() / free() even on programs for which you have the binary only. I think the most convenient way is to influence the linking order of your binary with LD_PRELOAD. Unfortunately Windows hasn't such facilities. So what are the possible alternatives to have a drop-in replacement for malloc() / free() with Windows ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|