MCPcopy Create free account
hub / github.com/ZettaScaleLabs/stabby / alloc_array

Method alloc_array

stabby-abi/src/alloc/mod.rs:383–388  ·  view source on GitHub ↗

Allocates a pointer to an array of `capacity` `T`, prefixed by an [`AllocPrefix`]

(alloc: &mut Alloc, capacity: usize)

Source from the content-addressed store, hash-verified

381impl<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) })

Callers

nothing calls this directly

Calls 3

concatMethod · 0.80
allocMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected