From 60a9104f6b737976e30271ac1c1a432cd9a5c657 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Wed, 9 Feb 2022 17:25:28 +0000 Subject: Encode ref count in bit mask too --- memory.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'memory.c') diff --git a/memory.c b/memory.c index 8bca068..f1ff3a3 100644 --- a/memory.c +++ b/memory.c @@ -57,13 +57,13 @@ freearray(Array *a) { if(a == nil) return; - if(a->refs == 0){ + if(GetRefs(a) == 0){ print("NEGATIVE REF COUNT (array)! %p\n", a); threadexitsall(nil); } - a->refs--; - if(a->refs == 0){ + SetRefs(a, GetRefs(a)-1); + if(GetRefs(a) == 0){ if(GetType(a) == AtypeArray) for(int i = 0; i < GetSize(a); i++) freearray(a->arraydata[i]); @@ -82,9 +82,9 @@ allocarray(arrayDataType t, int rank, int size) SetType(a, t); SetSize(a, size); SetStrand(a, 0); + SetRefs(a, 1); a->shape = emalloc(sizeof(*a->shape) * rank); a->rawdata = emalloc(datasizes[t] * size); - a->refs = 1; arrayalloccounts++; return a; } @@ -92,7 +92,7 @@ allocarray(arrayDataType t, int rank, int size) void incarrayref(Array *a) { - a->refs++; + SetRefs(a, GetRefs(a)+1); } Datum * -- cgit v1.2.3