1
/* Memory allocation manager */
2
/* $Id: memory.c,v 1.15 2003/12/21 14:56:56 zas Exp $ */
13
#include "util/error.h"
14
#include "util/memory.h"
17
#if !defined(LEAK_DEBUG) && !defined(FASTMEM)
19
static int alloc_try = 0;
22
patience(unsigned char *of)
25
if (alloc_try < ALLOC_MAXTRIES) {
26
ERROR("Out of memory (%s returned NULL): retry #%d,"
27
" I still exercise my patience and retry tirelessly.",
33
#ifdef CRASH_IF_ALLOC_MAXTRIES
34
INTERNAL("Out of memory (%s returned NULL) after %d tries,"
35
" I give up. See ya on the other side.",
38
ERROR("Out of memory (%s returned NULL) after %d tries,"
39
" I give up and try to continue. Pray for me, please.",
47
mem_alloc(size_t size)
51
void *p = malloc(size);
54
} while (patience("malloc"));
60
mem_calloc(size_t count, size_t eltsize)
64
void *p = calloc(count, eltsize);
67
} while (patience("calloc"));
76
INTERNAL("mem_free(NULL)");
84
mem_realloc(void *p, size_t size)
86
if (!p) return mem_alloc(size);
90
void *p2 = realloc(p, size);
93
} while (patience("realloc"));