Implement LinkedListAllocator::size_align

This commit is contained in:
Philipp Oppermann
2020-01-10 13:00:16 +01:00
parent a5c50e7408
commit 2001814119
2 changed files with 14 additions and 0 deletions

View File

@@ -103,6 +103,19 @@ impl LinkedListAllocator {
// region suitable for allocation
Ok(alloc_start)
}
/// Adjust the given layout so that the resulting allocated memory
/// region is also capable of storing a `ListNode`.
///
/// Returns the adjusted size and alignment as a (size, align) tuple.
fn size_align(layout: Layout) -> (usize, usize) {
let layout = layout
.align_to(mem::align_of::<ListNode>())
.expect("adjusting alignment failed")
.pad_to_align();
let size = layout.size().max(mem::size_of::<ListNode>());
(size, layout.align())
}
}
unsafe impl GlobalAlloc for Locked<LinkedListAllocator> {