00001 00015 #include "freelist.h" 00016 #include "danerror.h" 00017 #include "callcpp.h" 00018 00019 #include <memory.h> 00020 00021 static int mem_alloc_counter = 0; 00022 00026 int *memalloc_p(int size) { 00027 mem_alloc_counter++; 00028 if (!size) 00029 DoError (0, "Allocation of 0 bytes"); 00030 return ((int *) c_alloc_mem_p (size)); 00031 } 00032 00033 00037 int *memalloc(int size) { 00038 mem_alloc_counter++; 00039 return ((int *) c_alloc_mem (size)); 00040 } 00041 00042 00046 int *memrealloc(void *ptr, int size, int oldsize) { 00047 int shiftsize; 00048 int *newbuf; 00049 00050 shiftsize = size > oldsize ? oldsize : size; 00051 newbuf = (int *) c_alloc_mem (size); 00052 memcpy(newbuf, ptr, shiftsize); 00053 c_free_mem(ptr); 00054 return newbuf; 00055 } 00056 00057 00061 void memfree(void *element) { 00062 if (element) { 00063 c_free_mem(element); 00064 mem_alloc_counter--; 00065 } 00066 else { 00067 cprintf ("%d MEM_ALLOC's used\n", mem_alloc_counter); 00068 DoError (0, "Memfree of NULL pointer"); 00069 } 00070 } 00071 00072 00076 void mem_tidy(int level) { 00077 c_check_mem ("Old tidy", level); 00078 }