Skip to content

Commit

Permalink
update comment about using aligned_alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 11, 2024
1 parent ef15976 commit f6a480a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion library/std/src/sys/pal/unix/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ cfg_if::cfg_if! {
} else if #[cfg(target_os = "wasi")] {
#[inline]
unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
// C11 aligned_alloc requires that the size be a multiple of the alignment.
// C18 allows the implementation to return null if the alignment is "not supported", and
// some implementations, like wasi, choose to not support the case where the size is not
// a multiple of the alignment. This potentially wastes a bunch of space, but there's
// not a lot we can do about it.
// Layout already checks that the size rounded up doesn't overflow isize::MAX.
let align = layout.align();
let size = layout.size().next_multiple_of(align);
Expand Down

0 comments on commit f6a480a

Please sign in to comment.