Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages committed 2025-01-20 16:06:27 +08:00
commit 49c6b24a7a
25 files changed
+8401

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
/// SAFETY: the returned Vec must not be resized or reserverd
pub unsafe fn aligned_u8_vec(cap: usize, align: usize) -> Vec<u8> {
use std::alloc::*;
let layout =
Layout::from_size_align(cap, align).expect("invalid aligned value, must be power of 2");
unsafe {
let ptr = alloc(layout);
if ptr.is_null() {
panic!("failed to allocate {} bytes", cap);
}
Vec::from_raw_parts(ptr, 0, cap)
}
}