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

Method alloc

nodedb/src/bridge/slab.rs:89–103  ·  view source on GitHub ↗

Allocate a slab page and write data into it. Returns `Some(SlabId)` if a page is available and the data fits. Returns `None` if the pool is exhausted or the data exceeds page size.

(&mut self, data: &[u8])

Source from the content-addressed store, hash-verified

87 /// Returns `Some(SlabId)` if a page is available and the data fits.
88 /// Returns `None` if the pool is exhausted or the data exceeds page size.
89 pub fn alloc(&mut self, data: &[u8]) -> Option<SlabId> {
90 if data.len() > self.page_size {
91 return None; // Oversized — caller falls back to Arc<[u8]>.
92 }
93 let page_index = self.free_list.pop()?;
94 let offset = page_index as usize * self.page_size;
95 self.memory[offset..offset + data.len()].copy_from_slice(data);
96 self.alloc_count += 1;
97
98 Some(SlabId {
99 core_id: self.core_id,
100 page_index,
101 len: data.len() as u32,
102 })
103 }
104
105 /// Read data from a slab page by ID.
106 ///

Callers 4

alloc_and_readFunction · 0.45
alloc_exhaustionFunction · 0.45
free_and_reuseFunction · 0.45
utilizationFunction · 0.45

Calls 1

lenMethod · 0.45

Tested by 4

alloc_and_readFunction · 0.36
alloc_exhaustionFunction · 0.36
free_and_reuseFunction · 0.36
utilizationFunction · 0.36