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

Method alloc

nodedb/src/engine/kv/slab.rs:52–67  ·  view source on GitHub ↗

Allocate a slot. Returns the slot index, or None if the tier is full (caller should grow the tier).

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

Source from the content-addressed store, hash-verified

50 /// Allocate a slot. Returns the slot index, or None if the tier is full
51 /// (caller should grow the tier).
52 fn alloc(&mut self, data: &[u8]) -> Option<u32> {
53 debug_assert!(data.len() <= self.slot_size);
54
55 if let Some(slot_idx) = self.free_list.pop() {
56 let offset = slot_idx as usize * self.slot_size;
57 self.buf[offset..offset + data.len()].copy_from_slice(data);
58 // Zero remaining bytes in the slot (deterministic reads).
59 if data.len() < self.slot_size {
60 self.buf[offset + data.len()..offset + self.slot_size].fill(0);
61 }
62 self.occupied += 1;
63 Some(slot_idx)
64 } else {
65 None // Tier full — caller must grow.
66 }
67 }
68
69 /// Grow the tier by doubling its capacity.
70 fn grow(&mut self) {

Callers 8

basic_alloc_get_freeFunction · 0.45
large_object_fallbackFunction · 0.45
tier_grows_on_demandFunction · 0.45
tier_stats_populatedFunction · 0.45
used_bytes_and_capacityFunction · 0.45
store_value_inFunction · 0.45

Calls 7

tier_indexFunction · 0.85
encode_large_handleFunction · 0.85
encode_handleFunction · 0.85
growMethod · 0.80
lenMethod · 0.45
pushMethod · 0.45
to_vecMethod · 0.45

Tested by 7

basic_alloc_get_freeFunction · 0.36
large_object_fallbackFunction · 0.36
tier_grows_on_demandFunction · 0.36
tier_stats_populatedFunction · 0.36
used_bytes_and_capacityFunction · 0.36