diff runtime/fixed_alloc.c @ 89:5a195ee08eac

Fix memory leak and bug that was preventing First@Dictionary from working properly
author Mike Pavone <pavone@retrodev.com>
date Sat, 31 Jul 2010 00:19:15 -0400
parents d1569087348f
children e73a93fb5de1
line wrap: on
line diff
--- a/runtime/fixed_alloc.c	Fri Jul 30 19:52:54 2010 -0400
+++ b/runtime/fixed_alloc.c	Sat Jul 31 00:19:15 2010 -0400
@@ -1,6 +1,7 @@
 #include "fixed_alloc.h"
 #include <stdlib.h>
 #include <string.h>
+#include <stdio.h>
 
 uint16_t max_free[(MAX_SIZE-MIN_SIZE)/STRIDE];
 
@@ -19,6 +20,28 @@
 	return ret;
 }
 
+void print_mem_info(mem_manager * manager)
+{
+	int i,count,freeobjs;
+	mem_block * cur;
+	printf("Free blocks: %d\n", manager->freecount);
+	printf("Full Blocks: %d\n", manager->fullcount);
+	for (i = 0; i < (MAX_SIZE-MIN_SIZE)/STRIDE; i++)
+	{
+		count = 0;
+		freeobjs = 0;
+		cur = manager->inuse[i];
+		while(cur)
+		{
+			count++;
+			freeobjs += ((int)cur->numfree);
+			cur = cur->next;
+		}
+		printf("Bucket %d(size: %d) has %d blocks in use with %d total free slots\n", i, i*STRIDE+MIN_SIZE,count, freeobjs);
+	}
+	fflush(stdout);
+}
+
 void * falloc(size_t size, mem_manager * manager)
 {
 	uint16_t i,bit;
@@ -77,6 +100,7 @@
 	{
 		//Remove from linked list if there are no more free elements
 		manager->inuse[bucket] = block->next;
+		manager->fullcount++;
 		if(block->next)
 			block->next->last = block->last;
 	}
@@ -136,6 +160,7 @@
 		block->next = manager->inuse[bucket];
 		block->last = NULL;
 		manager->inuse[bucket] = block;
+		manager->fullcount--;
 		if(block->next)
 			block->next->last = block;
 	} else if(block->next && block->next->numfree < block->numfree) {