mimalloc icon indicating copy to clipboard operation
mimalloc copied to clipboard

Unable to intercept the dll

Open liuruicq opened this issue 6 months ago • 6 comments

According to the requirements of the document "Dynamic Override on Windows", I have checked and found that everything is in compliance. However, I still cannot intercept the dll files. I can only intercept them in the main program. How should I troubleshoot this?

liuruicq avatar Jun 10 '25 07:06 liuruicq

Is it necessary to use #include "mimalloc-overriding.h" separately for all DLLS and link the related DLLS

liuruicq avatar Jun 10 '25 15:06 liuruicq

DIfficult to say what is wrong:

  • make sure you did follow all instructions -- is mimalloc-redirect.dll in the same directory as the executable?
  • run with MIMALLOC_VERBOSE=1 in the environment to see verbose output and check if at startup you see that "mimalloc is redirected"
  • run minject -l <myexe> to see if mimalloc.dll is linked early in the import list

daanx avatar Jun 10 '25 17:06 daanx

DIfficult to say what is wrong:

  • make sure you did follow all instructions -- is in the same directory as the executable?mimalloc-redirect.dll
  • run with in the environment to see verbose output and check if at startup you see that "mimalloc is redirected"MIMALLOC_VERBOSE=1
  • run to see if is linked early in the import listminject -l <myexe>``mimalloc.dll

Image

Image It has been set as required. So how can I determine which DLLs this program relies on and that they are all allocated through mimalloc? The information I obtained through mi_stats_print is as follows. Can this prove that the called DLL is already using mimalloc?

Image

liuruicq avatar Jun 11 '25 01:06 liuruicq

Hello, after searching for information over the past two days, I seem to have understood how to use mimalloc.

Based on your descriptions in #535, #258, and #624, my understanding is as follows:

On Windows, since each DLL/EXE (module) has its own namespace, for C++, you should include #include <mimalloc-new-delete.h> once in a single .cpp file of each module to replace the default new/delete implementations for better performance. However, even if you don’t include mimalloc-new-delete.h, the basic malloc/free interception and replacement is achieved via mimalloc-redirect.dll, so mimalloc’s malloc/free will still be used. On Unix systems, enabling MI_OVERRIDE=ON when compiling mimalloc is sufficient, and there is no need to include #include <mimalloc-new-delete.h>.

To verify if mimalloc is in use, run the command: set MIMALLOC_VERBOSE=1 in CMD, then execute the program in CMD. If the message "mimalloc is redirected" appears, it indicates successful activation.

liuruicq avatar Jun 12 '25 01:06 liuruicq

Thanks. I hope it is working now for you?

daanx avatar Jun 14 '25 19:06 daanx

Thanks. I hope it is working now for you?

Thank you. He has resumed normal work now.

liuruicq avatar Jun 17 '25 00:06 liuruicq