From d464a1d3a62d620b6336131c355467bdc273e3c5 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Sat, 15 Jan 2022 13:03:11 +0000 Subject: Rework printer to add vertical padding too --- memory.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'memory.c') diff --git a/memory.c b/memory.c index fd0fec6..04c716d 100644 --- a/memory.c +++ b/memory.c @@ -1,10 +1,32 @@ #include #include #include +#include #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++; -- cgit v1.2.3