mimalloc icon indicating copy to clipboard operation
mimalloc copied to clipboard

Debug memory allocation

Open ahoarau opened this issue 1 year ago • 1 comments

Hi, I would like to debug memory allocations at runtime. Is there some kind of callback we can provide to instrumentalize our code ? Something like:

   // Starting from here, memory allocations are not allowed
    mi_set_option(mi_option_enable_allocations, 0);
    auto* p = malloc(100); /// --> calls abort() or throws an exception
   void on_alloc() {
        std::print("Allocations detected !");
   }
   // Setup a callback for anything allocation related
    mi_set_callback(&on_alloc);
    auto* p = malloc(100); /// --> calls on_alloc()

Thanks for your help !

ahoarau avatar Apr 07 '24 12:04 ahoarau

@daanx any thoughts ?

ahoarau avatar May 14 '24 05:05 ahoarau

Fixed with the new realtime sanitizer in clang 20 👍

ahoarau avatar Jul 29 '25 13:07 ahoarau