diff options
author | Peter Mikkelsen <peter@pmikkelsen.com> | 2022-02-09 17:06:41 +0000 |
---|---|---|
committer | Peter Mikkelsen <peter@pmikkelsen.com> | 2022-02-09 17:06:41 +0000 |
commit | 36e45dfccb5e5321682c0ec24dead22cf40fcb16 (patch) | |
tree | 5b51a2f46d50c4ae2ae93e94bf337ca9af2f4348 /memory.c | |
parent | e195d66a333102924bae452ba09dc20cba4e96e6 (diff) |
Make the array type a tiny bit smaller, by packing control information into a bit array
Diffstat (limited to 'memory.c')
-rw-r--r-- | memory.c | 23 |
1 files changed, 11 insertions, 12 deletions
@@ -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; |