代码拉取完成,页面将自动刷新
/*
wrapper functions for system malloc -- keep malloc stats.
Truilkan@TMI - 92/04/17
*/
#define IN_MALLOC_WRAPPER
#define NO_OPCODES
#include "std.h"
#include "debugmalloc.h"
#include "my_malloc.h"
#include "md.h"
#undef NOISY_MALLOC
#ifdef NOISY_MALLOC
#define NOISY(x) printf(x)
#define NOISY1(x,y) printf(x,y)
#define NOISY2(x,y,z) printf(x,y,z)
#define NOISY3(w,x,y,z) printf(w,x,y,z)
#else
#define NOISY(x)
#define NOISY1(x,y)
#define NOISY2(x,y,z)
#define NOISY3(w,x,y,z)
#endif
void fatal PROT1V(char *);
typedef struct stats_s {
unsigned int free_calls, alloc_calls, realloc_calls;
} stats_t;
static stats_t stats;
void debugmalloc_init()
{
stats.free_calls = 0;
stats.alloc_calls = 0;
stats.realloc_calls = 0;
MDinit();
}
INLINE void *debugrealloc P4(void *, ptr, int, size, int, tag, char *, desc)
{
void *tmp;
if (size <= 0)
fatal("illegal size in debugrealloc()");
NOISY3("realloc: %i (%x), %s\n", size, ptr, desc);
stats.realloc_calls++;
tmp = (md_node_t *) ptr - 1;
if (MDfree(tmp)) {
tmp = (void *) REALLOC(tmp, size + MD_OVERHEAD);
MDmalloc(tmp, size, tag, desc);
return (md_node_t *) tmp + 1;
}
return (void *) 0;
}
INLINE void *debugmalloc P3(int, size, int, tag, char *, desc)
{
void *tmp;
if (size <= 0)
fatal("illegal size in debugmalloc()");
stats.alloc_calls++;
tmp = (void *) MALLOC(size + MD_OVERHEAD);
MDmalloc(tmp, size, tag, desc);
NOISY3("malloc: %i (%x), %s\n", size, (md_node_t *)tmp + 1, desc);
return (md_node_t *) tmp + 1;
}
INLINE void *debugcalloc P4(int, nitems, int, size, int, tag, char *, desc)
{
void *tmp;
if (size <= 0)
fatal("illegal size in debugcalloc()");
stats.alloc_calls++;
tmp = (void *) CALLOC(nitems * size + MD_OVERHEAD, 1);
MDmalloc(tmp, nitems * size, tag, desc);
NOISY3("calloc: %i (%x), %s\n", nitems*size, (md_node_t *)tmp + 1, desc);
return (md_node_t *) tmp + 1;
}
INLINE void debugfree P1(void *, ptr)
{
md_node_t *tmp;
NOISY1("free (%x)\n", ptr);
stats.free_calls++;
tmp = (md_node_t *) ptr - 1;
if (MDfree(tmp)) {
memset(ptr, 'x', tmp->size);
FREE(tmp); /* only free if safe to do so */
}
}
void dump_malloc_data P1(outbuffer_t *, ob)
{
int net;
net = stats.alloc_calls - stats.free_calls;
outbuf_add(ob, "using debug malloc:\n\n");
outbuf_addv(ob, "total malloc'd: %10lu\n", total_malloced);
outbuf_addv(ob, "high water mark: %10lu\n", hiwater);
outbuf_addv(ob, "overhead: %10lu\n",
(MD_TABLE_SIZE * sizeof(md_node_t *)) + (net * MD_OVERHEAD));
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", net);
outbuf_addv(ob, "#realloc calls: %10lu\n", stats.realloc_calls);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。