压倒一切的malloc登录分配大小 [英] Overriding malloc to log allocation size

查看:233
本文介绍了压倒一切的malloc登录分配大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用code一点点登录tcpdump的mallocs我的一个项目中,code我使用因此是:

i'm trying to use a little bit of code to log mallocs in tcpdump for a project of mine, the code i'm using is thus:

#include <stdlib.h>


unsigned int memCount = 0;

void *my_malloc(size_t size) {
void *p = malloc(size);
memCount = memCount + size;
printf("Memory Allocated :%u \n", size
return p;
}

#define malloc(size) my_malloc(size)

看着很多类似的问题后在网上似乎这个应该工作,但是我的自定义的malloc似乎并没有越来越调用。任何帮助将大大pciated AP $ P $,谢谢!

After looking at many similar questions online it seems that this should work, however my custom malloc does not seem to be getting called. Any help would be much appreciated, thanks!

推荐答案

您必须的#define 中的每个源文件中的malloc宏观再次 - 这样做通过包括在宏定义的头文件。

You have to #define the malloc macro in each source file again - thus do it by including a header file where the macro is defined.

这篇关于压倒一切的malloc登录分配大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆