MCPcopy Create free account
hub / github.com/digama0/lean-sys / alloc

Method alloc

src/alloc.rs:21–35  ·  view source on GitHub ↗
(&self, layout: Layout)

Source from the content-addressed store, hash-verified

19
20unsafe impl GlobalAlloc for LeanAlloc {
21 unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
22 let alignment = layout.align().max(LEAN_OBJECT_SIZE_DELTA);
23 let offset = layout.size().wrapping_neg() & (alignment - 1);
24 let size = layout.size() + offset;
25
26 #[cfg(feature = "small_allocator")]
27 if alignment == LEAN_OBJECT_SIZE_DELTA && size <= crate::LEAN_MAX_SMALL_OBJECT_SIZE as usize
28 {
29 let slot_idx = crate::lean_get_slot_idx(size as _);
30 return crate::lean_alloc_small(size as _, slot_idx).cast();
31 }
32
33 lean_inc_heartbeat();
34 aligned_alloc(alignment, size)
35 }
36
37 #[allow(unused_variables)]
38 unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {

Callers

nothing calls this directly

Calls 1

lean_get_slot_idxFunction · 0.85

Tested by

no test coverage detected