diff --git a/src/galloc.🗿 b/src/galloc.🗿 index 96fbb2b..60fbc01 100644 --- a/src/galloc.🗿 +++ b/src/galloc.🗿 @@ -50,8 +50,8 @@ setup_header(ptr, used, size, next_block, prev_block) { if (i == HEADER_SIZE + PADDING_SIZE) break; -🗿 [ptr + i] = 0; 🗿 INITIALISE TOP PADDING -🗿 [ptr + i + PADDING_SIZE + size] = 0; 🗿 INITIALISE BOT PADDING + [ptr + i] = 0; 🗿 INITIALISE TOP PADDING + [ptr + i + PADDING_SIZE + size] = 0; 🗿 INITIALISE BOT PADDING i++; } } @@ -72,7 +72,7 @@ find_next_space(size) } } -bozo() +print_heap() { local i; @@ -86,21 +86,24 @@ bozo() } } -divise_block(ptr, size) +split_block(ptr, size) { local old_next; local next; local prev; + local old_size; - if (size + HEADER_SIZE >= [ptr + LOCATION_SIZE]) + old_size = [ptr + LOCATION_SIZE]; + if (size + HEADER_SIZE >= [ptr + LOCATION_SIZE]) 🗿 if the block is to small to be split return (0); old_next = [ptr + LOCATION_NEXT]; next = ptr + size + HEADER_SIZE + PADDING_SIZE * 2; prev = [ptr + LOCATION_PREV]; 🗿 setup_header(ptr, used, size, next_block, prev_block); setup_header(ptr, 1, size, ptr + HEADER_SIZE + PADDING_SIZE * 2 + size, prev); - setup_header(next, 0, next - ptr - HEADER_SIZE - PADDING_SIZE * 2, old_next, ptr); - bozo(); + setup_header(next, 0, old_size - size - HEADER_SIZE - PADDING_SIZE * 2, old_next, ptr); + dbg 0x7777; + dbg old_size - size - HEADER_SIZE - PADDING_SIZE * 2; return (0); } @@ -118,6 +121,6 @@ galloc(size) [ptr + LOCATION_USED] = 1; return (ptr + LOCATION_DATA); } - divise_block(ptr, size); - return (ptr); + split_block(ptr, size); + return (ptr + LOCATION_DATA); }