Heap: Avoid magic numbers
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2022-12-06 19:05:00 +01:00
parent b5c6ae253d
commit d48eb85d1d
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -29,6 +29,8 @@ struct HeapBlock : DoublyLinkedListNode<HeapBlock>
static_assert(sizeof(HeapBlock) == 48UL);
static const isize HEAP_BLOCK_SIZE = 48;
static DoublyLinkedList<HeapBlock> heap;
static Result<HeapBlock*> allocate_pages(usize count)
@ -64,14 +66,15 @@ static usize space_available(HeapBlock* block)
return block->full_size - block->req_size;
}
// The heap block is stored right behind a memory block.
static HeapBlock* get_heap_block_for_pointer(void* ptr)
{
return (HeapBlock*)offset_ptr(ptr, -48);
return (HeapBlock*)offset_ptr(ptr, -HEAP_BLOCK_SIZE);
}
static void* get_pointer_from_heap_block(HeapBlock* block)
{
return (void*)offset_ptr(block, 48);
return (void*)offset_ptr(block, HEAP_BLOCK_SIZE);
}
static usize get_fair_offset_to_split_at(HeapBlock* block, usize min)