From ae003d1854021bdbc3128b2752198761d06772fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Wed, 22 Apr 2020 20:16:30 -0300 Subject: Refactor page structure Changed the page's memory alignment to hopefully use less space. Also renamed buffer to elements. --- page.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'page.c') diff --git a/page.c b/page.c index b945ef8..9a712ed 100644 --- a/page.c +++ b/page.c @@ -5,17 +5,17 @@ #define PAGE_SIZE 4096 struct page { - uint8_t *buffer; + uint8_t *elements; + struct page *next; + struct page *prev; uint16_t gap_start; uint16_t gap_end; uint16_t element_count; - struct page *next; - struct page *prev; }; struct page *new_page() { struct page *result = malloc(sizeof(struct page)); - result->buffer = malloc(PAGE_SIZE); + result->elements = malloc(PAGE_SIZE); result->gap_start = 0; result->gap_end = PAGE_SIZE; result->next = 0; @@ -26,7 +26,7 @@ struct page *new_page() { void split_page(struct page *back) { struct page *front = new_page(); - memcpy(front->buffer, back->buffer + PAGE_SIZE / 2, PAGE_SIZE / 2); + memcpy(front->elements, back->elements + PAGE_SIZE / 2, PAGE_SIZE / 2); front->gap_start = PAGE_SIZE / 2; front->gap_end = PAGE_SIZE; @@ -55,7 +55,7 @@ void free_page(struct page *page) { } void move_gap_forward(struct page *page) { - page->buffer[page->gap_start] = page->buffer[page->gap_end]; + page->elements[page->gap_start] = page->elements[page->gap_end]; page->gap_start++; page->gap_end++; } @@ -63,5 +63,5 @@ void move_gap_forward(struct page *page) { void move_gap_backward(struct page *page) { page->gap_end--; page->gap_start--; - page->buffer[page->gap_end] = page->buffer[page->gap_start]; + page->elements[page->gap_end] = page->elements[page->gap_start]; } -- cgit v1.2.3