diff options
Diffstat (limited to 'memory.c')
-rw-r--r-- | memory.c | 28 |
1 files changed, 25 insertions, 3 deletions
@@ -1,10 +1,32 @@ #include <u.h> #include <libc.h> #include <bio.h> +#include <pool.h> #include "apl9.h" int alloccounts = 0; +int debugmem; + +void * +emalloc(ulong size) +{ + void *res = malloc(size); + if(res == nil){ + print("Out of memory! :(\n"); + exits("emalloc"); + } + return res; +} + +void +checkmem(char *where) +{ + if(debugmem){ + print("Checking memory at: %s\n", where); + poolcheck(mainmem); + } +} void freearray(Array *a) @@ -32,13 +54,13 @@ freearray(Array *a) Array * allocarray(arrayDataType t, int rank, int size) { - Array *a = malloc(sizeof(Array)); + Array *a = emalloc(sizeof(Array)); a->rank = rank; a->type = t; a->size = size; a->stranded = 0; - a->shape = malloc(sizeof(int) * rank); - a->rawdata = malloc(datasizes[t] * size); + a->shape = emalloc(sizeof(int) * rank); + a->rawdata = emalloc(datasizes[t] * size); a->type = t; a->refs = 1; alloccounts++; |