removed malloc and changed free_list list
This commit is contained in:
parent
1d1c70c945
commit
b48ada3663
12
mm.c
12
mm.c
@ -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];
|
static size_t list_sizes[NUM_LISTS];
|
||||||
|
|
||||||
/* Function prototypes for internal helper routines */
|
/* Function prototypes for internal helper routines */
|
||||||
@ -153,9 +153,9 @@ int mm_init(void)
|
|||||||
initial[3] = FENCE; /* Epilogue header */
|
initial[3] = FENCE; /* Epilogue header */
|
||||||
|
|
||||||
for (int i = 0; i < NUM_LISTS; i++) {
|
for (int i = 0; i < NUM_LISTS; i++) {
|
||||||
struct list *current_list = malloc(sizeof(struct list));
|
|
||||||
list_init(current_list);
|
list_init(&free_lists[i]);
|
||||||
free_lists[i] = current_list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < NUM_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++) {
|
for (int i = 0; i < NUM_LISTS; i++) {
|
||||||
if ((n_words <= list_sizes[i]) || (i == (NUM_LISTS - 1))) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
return free_lists[i];
|
return &free_lists[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user