加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
wrappedmalloc.c 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
luanhailiang 提交于 2012-08-09 20:44 . My mudos
/*
wrapper functions for system malloc -- keep malloc stats.
Truilkan@TMI - 92/04/17
*/
#define IN_MALLOC_WRAPPER
#define NO_OPCODES
#include "std.h"
#include "my_malloc.h"
#include "lpc_incl.h"
#include "comm.h"
typedef struct stats_s {
unsigned int free_calls, alloc_calls, realloc_calls;
} stats_t;
static stats_t stats;
void wrappedmalloc_init()
{
stats.free_calls = 0;
stats.alloc_calls = 0;
stats.realloc_calls = 0;
}
INLINE void *wrappedrealloc P2(void *, ptr, int, size)
{
stats.realloc_calls++;
return (void *) REALLOC(ptr, size);
}
INLINE void *wrappedmalloc P1(int, size)
{
stats.alloc_calls++;
return (void *) MALLOC(size);
}
INLINE void *wrappedcalloc P2(int, nitems, int, size)
{
stats.alloc_calls++;
return (void *) CALLOC(nitems, size);
}
INLINE void wrappedfree P1(void *, ptr)
{
stats.free_calls++;
FREE(ptr);
}
void dump_malloc_data P1(outbuffer_t *, ob)
{
outbuf_add(ob, "using wrapped malloc:\n\n");
outbuf_addv(ob, "#alloc calls: %10lu\n", stats.alloc_calls);
outbuf_addv(ob, "#free calls: %10lu\n", stats.free_calls);
outbuf_addv(ob, "#alloc - #free: %10lu\n",
stats.alloc_calls - stats.free_calls);
outbuf_addv(ob, "#realloc calls: %10lu\n", stats.realloc_calls);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化