Jędrzej Dudkiewicz
Jędrzej Dudkiewicz

Reputation: 1122

How to replace newlib's malloc

I'm using LPCXpresso with LPC1768. I'm trying to implement few memory pools. I have my old code that allows this, so I'm fine there. What I'm unable to do is to prevent newlib from using it's own malloc. There are few functions in newlib calling malloc. I dodged them all, except for _Csys_alloc, which is unfortunately called by _initio. Since malloc isn't weak, I can't simply replace it with my own implementation. So is there any other way to do it except for either modifying newlib and recompiling or writing my own _initio routine?

Thanks for your help.

Upvotes: 2

Views: 2580

Answers (1)

Clifford
Clifford

Reputation: 93476

It is perhaps simplest to let Newlib use its malloc as it wants and implement _sbrk() to limit its use and location to a static pool sized to just what is needed for library initialisation, then override malloc() for use in your own code - the linker will only link to standard library symbols if not previously found in another library of object code.

Upvotes: 1

Related Questions