From 36e45dfccb5e5321682c0ec24dead22cf40fcb16 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Wed, 9 Feb 2022 17:06:41 +0000 Subject: Make the array type a tiny bit smaller, by packing control information into a bit array --- memory.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'memory.c') diff --git a/memory.c b/memory.c index 33c30d7..8bca068 100644 --- a/memory.c +++ b/memory.c @@ -57,34 +57,33 @@ freearray(Array *a) { if(a == nil) return; + if(a->refs == 0){ + print("NEGATIVE REF COUNT (array)! %p\n", a); + threadexitsall(nil); + } a->refs--; if(a->refs == 0){ - if(a->type == AtypeArray) - for(int i = 0; i < a->size; i++) + if(GetType(a) == AtypeArray) + for(int i = 0; i < GetSize(a); i++) freearray(a->arraydata[i]); free(a->shape); free(a->rawdata); free(a); arrayalloccounts--; - }else if(a->refs < 0){ - print("NEGATIVE REF COUNT (array)! %p\n", a); - threadexitsall(nil); } - } Array * allocarray(arrayDataType t, int rank, int size) { Array *a = emalloc(sizeof(Array)); - a->rank = rank; - a->type = t; - a->size = size; - a->stranded = 0; - a->shape = emalloc(sizeof(int) * rank); + SetRank(a, rank); + SetType(a, t); + SetSize(a, size); + SetStrand(a, 0); + a->shape = emalloc(sizeof(*a->shape) * rank); a->rawdata = emalloc(datasizes[t] * size); - a->type = t; a->refs = 1; arrayalloccounts++; return a; -- cgit v1.2.3