【发布时间】:2010-07-06 07:06:12
【问题描述】:
我想在我的代码中使用 git 的 malloc 和 realloc 包装器来应对 OOM(内存不足)情况。这是它的代码:
void *xmalloc(size_t size)
{
void *ret = malloc(size);
if (!ret && !size)
ret = malloc(1);
if (!ret) {
release_pack_memory(size, -1);
ret = malloc(size);
if (!ret && !size)
ret = malloc(1);
if (!ret)
die("Out of memory, malloc failed");
}
#ifdef XMALLOC_POISON
memset(ret, 0xA5, size);
#endif
return ret;
}
但是 release_pack_memory 函数在 sha1_file.c 头文件中,并且该函数引用了 Git 代码中其他头文件中的函数,我不想花太多精力将这个函数与 Git 的代码库隔离。目前我正在寻找 release_pack_memory 函数的替代函数,或者你能推荐我另一个替代函数。我会感谢任何形式的帮助
【问题讨论】: