microsoft / mimalloc

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

Debug memory allocation #875

Open ahoarau opened 2 months ago

ahoarau commented 2 months ago

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 commented 1 month ago

@daanx any thoughts ?