I came across a case where we wanted to add custom memory debug/tracking code for malloc. Since pico sdk already wraps malloc we need a way of calling our code from the wrapped pico version of malloc. I had 2 ideas to accomplish this.
Add CMAKE switch to turn off building of pico_malloc so user could implement wrap functions on their own.
Create new PICO_REDIRECT_MALLOC define, if enabled it would replace REAL_FUNC, with REDIRECT_MALLOC_FUNC.
My preference is option 2 as it allows user to still get the functionally in the pico_malloc wrapped functions and just extend it with more functionality.
I came across a case where we wanted to add custom memory debug/tracking code for malloc. Since pico sdk already wraps malloc we need a way of calling our code from the wrapped pico version of malloc. I had 2 ideas to accomplish this.
My preference is option 2 as it allows user to still get the functionally in the pico_malloc wrapped functions and just extend it with more functionality.
I have my suggested changes at https://github.com/JNTeledyne/pico-sdk/commit/399cdae0f21a1bb58e709156eeb74a2b002062c6
Another good use of this is if someone wanted to have fun and implement a slab allocator or write their own version of malloc.