Simple C implementation to track memory malloc/free?

后端 未结 7 1465
情歌与酒
情歌与酒 2020-12-01 13:32

programming language: C platform: ARM Compiler: ADS 1.2

I need to keep track of simple melloc/free calls in my project. I just need to get very basic id

7条回答
  •  离开以前
    2020-12-01 14:02

    You could allocate a few extra bytes in your wrapper and put either an id (if you want to be able to couple malloc() and free()) or just the size there. Just malloc() that much more memory, store the information at the beginning of your memory block and and move the pointer you return that many bytes forward.

    This can, btw, also easily be used for fence pointers/finger-prints and such.

提交回复
热议问题