comparison runtime/fixed_alloc.c @ 119:72c648bca43b

Improved memory debug output and fixed memory leak in Array
author Mike Pavone <pavone@retrodev.com>
date Mon, 18 Oct 2010 00:50:18 -0400
parents 43cc42df26cc
children
comparison
equal deleted inserted replaced
118:b3f56e1d54a0 119:72c648bca43b
43 printf("Bucket %d(size: %d) has %d blocks in use with %d free slots out of %d\n", i, i*STRIDE+MIN_SIZE,count, freeobjs, max_free[i]*count); 43 printf("Bucket %d(size: %d) has %d blocks in use with %d free slots out of %d\n", i, i*STRIDE+MIN_SIZE,count, freeobjs, max_free[i]*count);
44 } 44 }
45 fflush(stdout); 45 fflush(stdout);
46 } 46 }
47 47
48 void print_live_object_types(mem_manager * manager) 48 void find_live_objects_oftype(mem_manager * manager, int32_t type_id, void ** output)
49 { 49 {
50 object * obj; 50 object * obj;
51 mem_block * cur; 51 mem_block * cur;
52 int32_t i,j,bitslots,bit,*counts = malloc(sizeof(int32_t)*max_registered_type); 52 int32_t i,j,bitslots,bit,outpos=0;
53 for (i = 0; i < (MAX_SIZE-MIN_SIZE)/STRIDE; i++)
54 {
55 cur = manager->inuse[i];
56 while(cur)
57 {
58 bitslots = max_free[i]/8;
59 if(max_free[i]&7)
60 ++bitslots;
61 for(j = 0; j < bitslots; ++j)
62 if(cur->bitmap[j] != 0xFF)
63 {
64 for (bit = 0; bit < 8; ++bit)
65 {
66 if (!(cur->bitmap[j] & (1 << bit)))
67 {
68 obj = (object *)(((char *)cur)+BLOCK_SIZE-(((j*8+bit)+1)*(i*STRIDE+MIN_SIZE)));
69 if(obj->bprint->type_id == type_id)
70 output[outpos++] = obj;
71 }
72 }
73 }
74 cur = cur->next;
75 }
76 }
77 }
78
79 void get_live_object_counts(mem_manager * manager, int32_t * counts)
80 {
81 object * obj;
82 mem_block * cur;
83 int32_t i,j,bitslots,bit;
53 memset(counts, 0, sizeof(int32_t)*max_registered_type); 84 memset(counts, 0, sizeof(int32_t)*max_registered_type);
54 for (i = 0; i < (MAX_SIZE-MIN_SIZE)/STRIDE; i++) 85 for (i = 0; i < (MAX_SIZE-MIN_SIZE)/STRIDE; i++)
55 { 86 {
56 cur = manager->inuse[i]; 87 cur = manager->inuse[i];
57 while(cur) 88 while(cur)
72 } 103 }
73 } 104 }
74 cur = cur->next; 105 cur = cur->next;
75 } 106 }
76 } 107 }
108 }
109
110 void print_live_object_types(mem_manager * manager)
111 {
112 int32_t i,*counts = malloc(sizeof(int32_t)*max_registered_type);
113 get_live_object_counts(manager, counts);
77 for (i = 0; i < max_registered_type; ++i) 114 for (i = 0; i < max_registered_type; ++i)
78 if(counts[i]) 115 if(counts[i])
79 printf("%d live objects of type %d\n", counts[i], i); 116 printf("%d live objects of type %d\n", counts[i], i);
80 fflush(stdout); 117 fflush(stdout);
81 } 118 }