Browse Source

custom_malloc(): setting the block header at the right time for free lists, removed the debugging printf's

Ioannis Koutras 14 years ago
parent
commit
4be63813ab
1 changed files with 2 additions and 10 deletions
  1. 2 10
      custom_malloc.c

+ 2 - 10
custom_malloc.c

@@ -1,4 +1,3 @@
-#include <stdio.h>
 #include "custom_malloc.h"
 #include "posix_lock.h"
 #include "other.h"
@@ -16,13 +15,10 @@ void * custom_malloc(heap_t* heap, size_t size) {
 
 	posix_lock(heap);
 
-	printf("Searching for a free block of size %d.\n", size);
-
 	fixed_list_id = map_size_to_list(heap, size);
 	
 	// If a fixed list is found, do a first fit
 	if(fixed_list_id != -1) {
-		printf("Searching on fixed lists...\n");
 		current_maptable_node = heap->maptable_head;
 		// traverse through the maptable node list
 		if(fixed_list_id != 0) {
@@ -43,29 +39,25 @@ void * custom_malloc(heap_t* heap, size_t size) {
 		found = 0;
 
 		// first fit from free list
-		printf("Searching on the free list...\n", size);
 		for(current_block = heap->free_list_head; current_block != NULL; current_block = get_next(current_block)) {
 			if(get_size(current_block) >= size) {
 				ptr = current_block;
-				set_requested_size(ptr, size);
-				set_next(ptr, heap->used_blocks_head);
 				heap->used_blocks_head = ptr;
 				if(current_block != heap->free_list_head) {
 					set_next(previous_block, get_next(ptr));
 				} else {
 					heap->free_list_head = get_next(ptr);
 				}
+				set_requested_size(ptr, size);
+				set_next(ptr, heap->used_blocks_head);
 				posix_unlock(heap);
-				printf("Block found in the free list.\n");
 				return ptr;
 			}
 			previous_block = current_block;
 		}
 
 		if(!found) {
-			printf("No free available chunk was found.\n");
 			ptr = sys_alloc(heap, size);
-			printf("Chuck was given by the OS.\n");
 		}
 
 	}