Skip to content

Allow redirecting malloc functions to user defined functions #1716

@JNTeledyne

Description

@JNTeledyne

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.

  1. Add CMAKE switch to turn off building of pico_malloc so user could implement wrap functions on their own.
  2. 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 have my suggested changes at JNTeledyne@399cdae

Another good use of this is if someone wanted to have fun and implement a slab allocator or write their own version of malloc.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions