1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "mem.h"
// memory allocation
void rfx_free(void*ptr)
{
if(!ptr)
return;
free(ptr);
}
void start_debugger()
{
//*(int*)0=0;
}
void* rfx_alloc(int size)
{
void*ptr;
if(size == 0) {
//*(int*)0 = 0xdead;
//fprintf(stderr, "Warning: Zero alloc\n");
return 0;
}
ptr = malloc(size);
if(!ptr) {
fprintf(stderr, "FATAL: Out of memory (while trying to claim %d bytes)\n", size);
start_debugger();
exit(1);
}
return ptr;
}
void* rfx_realloc(void*data, int size)
{
void*ptr;
if(size == 0) {
//*(int*)0 = 0xdead;
//fprintf(stderr, "Warning: Zero realloc\n");
rfx_free(data);
return 0;
}
if(!data) {
ptr = malloc(size);
} else {
ptr = realloc(data, size);
}
if(!ptr) {
fprintf(stderr, "FATAL: Out of memory (while trying to claim %d bytes)\n", size);
start_debugger();
exit(1);
}
return ptr;
}
void* rfx_calloc(int size)
{
void*ptr;
if(size == 0) {
//*(int*)0 = 0xdead;
//fprintf(stderr, "Warning: Zero alloc\n");
return 0;
}
#ifdef HAVE_CALLOC
ptr = calloc(1, size);
#else
ptr = malloc(size);
#endif
if(!ptr) {
fprintf(stderr, "FATAL: Out of memory (while trying to claim %d bytes)\n", size);
start_debugger();
exit(1);
}
#ifndef HAVE_CALLOC
memset(ptr, 0, size);
#endif
return ptr;
}
#ifndef HAVE_CALLOC
void* rfx_calloc_replacement(int nmemb, int size)
{
rfx_calloc(nmemb*size);
}
#endif
#ifdef MEMORY_INFO
long rfx_memory_used()
{
}
char* rfx_memory_used_str()
{
}
#endif
|