Allocates a pointer to an array of `capacity` `T`, prefixed by an [`AllocPrefix`]
(alloc: &mut Alloc, capacity: usize)
| 381 | impl<T, Alloc: IAlloc> AllocPtr<T, Alloc> { |
| 382 | /// Allocates a pointer to a single element of `T`, prefixed by an [`AllocPrefix`] |
| 383 | pub fn alloc(alloc: &mut Alloc) -> Option<Self> { |
| 384 | Self::alloc_array(alloc, 1) |
| 385 | } |
| 386 | /// Allocates a pointer to an array of `capacity` `T`, prefixed by an [`AllocPrefix`] |
| 387 | pub fn alloc_array(alloc: &mut Alloc, capacity: usize) -> Option<Self> { |
| 388 | let mut layout = Layout::of::<AllocPrefix<Alloc>>().concat(Layout::array::<T>(capacity)); |
| 389 | layout.align = core::mem::align_of::<AllocPrefix<Alloc>>().max(layout.align); |
| 390 | let ptr = alloc.alloc(layout); |
| 391 | NonNull::new(ptr).map(|ptr| unsafe { Self::init(ptr, capacity) }) |