removed malloc and changed free_list list

This commit is contained in:
Micah Moore 2022-11-14 20:15:31 -05:00
parent 1d1c70c945
commit b48ada3663

12
mm.c
View File

@ -65,7 +65,7 @@ static size_t align(size_t size) {
}
static struct list *free_lists[NUM_LISTS];
static struct list free_lists[NUM_LISTS];
static size_t list_sizes[NUM_LISTS];
/* Function prototypes for internal helper routines */
@ -153,9 +153,9 @@ int mm_init(void)
initial[3] = FENCE; /* Epilogue header */
for (int i = 0; i < NUM_LISTS; i++) {
struct list *current_list = malloc(sizeof(struct list));
list_init(current_list);
free_lists[i] = current_list;
list_init(&free_lists[i]);
}
for (int i = 0; i < NUM_LISTS; i++) {
@ -372,10 +372,10 @@ static struct list* find_list(int not_empty, size_t n_words) {
for (int i = 0; i < NUM_LISTS; i++) {
if ((n_words <= list_sizes[i]) || (i == (NUM_LISTS - 1))) {
if (not_empty && list_empty(free_lists[i])) {
if (not_empty && list_empty(&free_lists[i])) {
continue;
}
return free_lists[i];
return &free_lists[i];
}
}
return NULL;