MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / new

Method new

nodedb/src/data/io/aligned_buf.rs:25–43  ·  view source on GitHub ↗

Allocate a new aligned buffer with at least `min_capacity` bytes.

(min_capacity: usize)

Source from the content-addressed store, hash-verified

23impl AlignedBuf {
24 /// Allocate a new aligned buffer with at least `min_capacity` bytes.
25 pub fn new(min_capacity: usize) -> std::io::Result<Self> {
26 let capacity = round_up(min_capacity.max(ALIGNMENT), ALIGNMENT);
27 let layout = std::alloc::Layout::from_size_align(capacity, ALIGNMENT)
28 .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, e))?;
29
30 let ptr = unsafe { std::alloc::alloc_zeroed(layout) };
31 if ptr.is_null() {
32 return Err(std::io::Error::new(
33 std::io::ErrorKind::OutOfMemory,
34 "aligned buffer allocation failed",
35 ));
36 }
37
38 Ok(Self {
39 ptr,
40 capacity,
41 layout,
42 })
43 }
44
45 /// Mutable raw pointer to the buffer start (for io_uring SQE submission).
46 #[inline]

Callers

nothing calls this directly

Calls 2

round_upFunction · 0.70
is_nullMethod · 0.45

Tested by

no test coverage detected