microsoft / mimalloc

mimalloc is a compact general purpose allocator with excellent performance.
MIT License
9.74k stars 793 forks source link

Override malloc in dynamically loaded dll on Windows #820

Open rvjr opened 8 months ago

rvjr commented 8 months ago

Dear all,

we're just trying to evaluate how to use mimalloc in a DLL project. We tried to use the dynamic override and used minject.exe to patch the dll load order to include mimalloc first. Unfortunately this whole approach is probably not suitable for our use case, because our DLL might be loaded dynamically be the user application (out of our control, we only supply the library). In that case we again get mimalloc-redirect: error: mimalloc-redirect.dll seems to be initialized after ucrtbase.dll, because the user application already loaded the CRT before loading our DLL dynamically.

What options do we have to use mimalloc in the Windows library anyway?

I had some issues with statically overriding a few years ago (https://github.com/microsoft/mimalloc/issues/268#issuecomment-870753622) and abandoned the mimalloc integration until now, but we again had some issues using the standard CRT allocator, so I'm trying to retry the integration now...

Best regards, Rainer