noun: add IndirectAtom::new_raw_mut_bytearray to allocate indirect atoms with mutable memory returned as a reference to a fixed-sized byte array.

This commit is contained in:
Edward Amsden 2023-12-21 07:51:44 -06:00
parent 9f88799fe2
commit 0f6c8b4659

View File

@ -441,6 +441,15 @@ impl IndirectAtom {
(noun, from_raw_parts_mut(ptr as *mut u8, size)) (noun, from_raw_parts_mut(ptr as *mut u8, size))
} }
/// Create an indirect atom backed by a fixed-size array
pub unsafe fn new_raw_mut_bytearray<'a, const N: usize, A: NounAllocator>(
allocator: &mut A,
) -> (Self, &'a mut [u8; N]) {
let word_size = (std::mem::size_of::<[u8; N]>() + 7) << 3;
let (noun, ptr) = Self::new_raw_mut_zeroed(allocator, word_size);
(noun, &mut *(ptr as *mut [u8; N]))
}
/** Size of an indirect atom in 64-bit words */ /** Size of an indirect atom in 64-bit words */
pub fn size(&self) -> usize { pub fn size(&self) -> usize {
unsafe { *(self.to_raw_pointer().add(1)) as usize } unsafe { *(self.to_raw_pointer().add(1)) as usize }