MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / try_alloc

Function try_alloc

crates/core/src/alloc.rs:34–44  ·  view source on GitHub ↗
(layout: Layout)

Source from the content-addressed store, hash-verified

32/// Same as `alloc::alloc::alloc`: layout must have non-zero size.
33#[inline]
34unsafe fn try_alloc(layout: Layout) -> Result<NonNull<u8>, OutOfMemory> {
35 // Safety: same as our safety conditions.
36 debug_assert!(layout.size() > 0);
37 let ptr = unsafe { std_alloc::alloc::alloc(layout) };
38
39 if let Some(ptr) = NonNull::new(ptr) {
40 Ok(ptr)
41 } else {
42 Err(OutOfMemory::new(layout.size()))
43 }
44}
45
46/// Tries to reallocate a block of memory, returning `OutOfMemory` on failure.
47///

Callers

nothing calls this directly

Calls 4

allocFunction · 0.85
OkFunction · 0.85
newFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected