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

Function basic_alloc_get_free

nodedb/src/engine/kv/slab.rs:387–405  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

385
386 #[test]
387 fn basic_alloc_get_free() {
388 let mut slab = SlabAllocator::new();
389
390 // Small value (fits in 64B tier).
391 let (h1, l1) = slab.alloc(b"hello");
392 assert_eq!(slab.get(h1, l1), b"hello");
393
394 // Medium value (fits in 256B tier).
395 let data = vec![0xAB; 200];
396 let (h2, l2) = slab.alloc(&data);
397 assert_eq!(slab.get(h2, l2), &data);
398
399 // Free and realloc.
400 slab.free(h1, l1);
401 let (h3, l3) = slab.alloc(b"world");
402 assert_eq!(slab.get(h3, l3), b"world");
403 // Should reuse the freed slot.
404 assert_eq!(h3, h1);
405 }
406
407 #[test]
408 fn large_object_fallback() {

Callers

nothing calls this directly

Calls 2

allocMethod · 0.45
freeMethod · 0.45

Tested by

no test coverage detected