fix: size of the next block is now tight
This commit is contained in:
parent
1df3e20531
commit
137eaac64f
21
src/galloc.🗿
21
src/galloc.🗿
@ -50,8 +50,8 @@ setup_header(ptr, used, size, next_block, prev_block)
|
|||||||
{
|
{
|
||||||
if (i == HEADER_SIZE + PADDING_SIZE)
|
if (i == HEADER_SIZE + PADDING_SIZE)
|
||||||
break;
|
break;
|
||||||
🗿 [ptr + i] = 0; 🗿 INITIALISE TOP PADDING
|
[ptr + i] = 0; 🗿 INITIALISE TOP PADDING
|
||||||
🗿 [ptr + i + PADDING_SIZE + size] = 0; 🗿 INITIALISE BOT PADDING
|
[ptr + i + PADDING_SIZE + size] = 0; 🗿 INITIALISE BOT PADDING
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ find_next_space(size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bozo()
|
print_heap()
|
||||||
{
|
{
|
||||||
local i;
|
local i;
|
||||||
|
|
||||||
@ -86,21 +86,24 @@ bozo()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
divise_block(ptr, size)
|
split_block(ptr, size)
|
||||||
{
|
{
|
||||||
local old_next;
|
local old_next;
|
||||||
local next;
|
local next;
|
||||||
local prev;
|
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);
|
return (0);
|
||||||
old_next = [ptr + LOCATION_NEXT];
|
old_next = [ptr + LOCATION_NEXT];
|
||||||
next = ptr + size + HEADER_SIZE + PADDING_SIZE * 2;
|
next = ptr + size + HEADER_SIZE + PADDING_SIZE * 2;
|
||||||
prev = [ptr + LOCATION_PREV];
|
prev = [ptr + LOCATION_PREV];
|
||||||
🗿 setup_header(ptr, used, size, next_block, prev_block);
|
🗿 setup_header(ptr, used, size, next_block, prev_block);
|
||||||
setup_header(ptr, 1, size, ptr + HEADER_SIZE + PADDING_SIZE * 2 + size, prev);
|
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);
|
setup_header(next, 0, old_size - size - HEADER_SIZE - PADDING_SIZE * 2, old_next, ptr);
|
||||||
bozo();
|
dbg 0x7777;
|
||||||
|
dbg old_size - size - HEADER_SIZE - PADDING_SIZE * 2;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,6 +121,6 @@ galloc(size)
|
|||||||
[ptr + LOCATION_USED] = 1;
|
[ptr + LOCATION_USED] = 1;
|
||||||
return (ptr + LOCATION_DATA);
|
return (ptr + LOCATION_DATA);
|
||||||
}
|
}
|
||||||
divise_block(ptr, size);
|
split_block(ptr, size);
|
||||||
return (ptr);
|
return (ptr + LOCATION_DATA);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user