Skip to content

Commit 1f57de9

Browse files
author
Andrew Flockhart
committed
WIP on master: c9a45e0 mm_check fixed
2 parents c9a45e0 + 4d55a60 commit 1f57de9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

mm.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ int mm_init(void)
7373
}
7474

7575
CLASS_SIZE[NUM_CLASSES] = (void*)NULL; //entry for MISC - bigger than biggest class
76-
76+
printf("top:%d\n",mem_heap_hi() );
77+
printf("bottom:%d\n",mem_heap_lo() );
78+
printf("init%d\n",mm_check());
7779
return 0;
7880
}
7981

@@ -103,6 +105,7 @@ int mm_init(void)
103105
void *mm_malloc(size_t size)/*{{{*/
104106
{
105107

108+
printf("mallocs%d\n",mm_check());
106109
int wasFound = 0; //will be 1 if block is found, 0 if not found
107110
int newsize = ALIGN(size) + OVERHEAD; //size to be malloc'ed out
108111
int oldsize; //size of free/sbrk'd block being used
@@ -152,7 +155,7 @@ void *mm_malloc(size_t size)/*{{{*/
152155
returnPointer = ((char*)(returnPointer) + 7);// now points to start of usable data
153156
*((char*)(returnPointer) + size) = 1; //mark as used at back
154157
}
155-
printf("%d\n",mm_check());
158+
printf("malloce%d\n",mm_check());
156159
return (void*)(returnPointer);
157160

158161
/* original naive code
@@ -180,6 +183,7 @@ void *mm_malloc(size_t size)/*{{{*/
180183
*/
181184
void mm_free(void *argptr)/*{{{*/
182185
{
186+
printf("free%d\n",mm_check());
183187
int size, csize;
184188
char* ptr = argptr;
185189

@@ -188,7 +192,7 @@ void mm_free(void *argptr)/*{{{*/
188192

189193
/*
190194
* Begin Coalescing
191-
*/
195+
*
192196
if(*(ptr - 6) == 0) { //the block BEFORE is a free block
193197
ptr = (char*)ptr - 6;
194198
csize = *((int*)ptr - 1); //size of the previous block
@@ -205,7 +209,9 @@ void mm_free(void *argptr)/*{{{*/
205209
size = size + csize + 16;
206210
}
207211
}
212+
*/
208213

214+
printf("%d",mm_check());
209215
mm_insert((void*)((char*)argptr - 8), size);
210216
}/*}}}*/
211217

@@ -214,6 +220,7 @@ void mm_free(void *argptr)/*{{{*/
214220
*/
215221
void *mm_realloc(void *ptr, size_t size)/*{{{*/
216222
{
223+
printf("%d",mm_check());
217224
void *oldptr = ptr;
218225
void *newptr;
219226
size_t copySize;
@@ -226,6 +233,7 @@ void *mm_realloc(void *ptr, size_t size)/*{{{*/
226233
copySize = size;
227234
memcpy(newptr, oldptr, copySize);
228235
mm_free(oldptr);
236+
printf("%d\n",mm_check());
229237
return newptr;
230238
}/*}}}*/
231239

@@ -252,7 +260,6 @@ int mm_check(void)/*{{{*/
252260
int i;
253261
int size;
254262
size_t* top_heap = mem_heap_hi();
255-
printf("top of heap: %d\n bottom of heap: %d\n", top_heap, mem_heap_lo());
256263

257264
for(i = 0; i < NUM_CLASSES; i++){//traverse free lists for integrity/*{{{*/
258265
next_ptr = CLASSES[i];
@@ -339,6 +346,7 @@ int mm_check(void)/*{{{*/
339346

340347
int mm_insert(void* location, int size) {/*{{{*/
341348

349+
printf("insert%d\n",mm_check());
342350
int i = 0;
343351
int flag = 1;
344352
size_t* last_ptr = NULL;
@@ -394,6 +402,7 @@ int mm_insert(void* location, int size) {/*{{{*/
394402
*(char*)location = 0; //mark free at back
395403
*((int*)location -1) = usableSize; //mark size at back
396404

405+
printf("inserte%d\n",mm_check());
397406
return 0;
398407
}
399408
}/*}}}*/

0 commit comments

Comments
 (0)