Heap: Avoid magic numbers
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b5c6ae253d
commit
d48eb85d1d
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user