MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / mi_page_malloc_zero

Function mi_page_malloc_zero

system/lib/mimalloc/src/alloc.c:32–44  ·  view source on GitHub ↗

Fast allocation in a page: just pop from the free list. Fall back to generic allocation only if the list is empty. Note: in release mode the (inlined) routine is about 7 instructions with a single test.

Source from the content-addressed store, hash-verified

30// Fall back to generic allocation only if the list is empty.
31// Note: in release mode the (inlined) routine is about 7 instructions with a single test.
32static mi_decl_forceinline void* mi_page_malloc_zero(mi_theap_t* theap, mi_page_t* page, size_t size, bool zero, size_t* usable) mi_attr_noexcept
33{
34 if (page->block_size != 0) { // not the empty theap
35 mi_assert_internal(mi_page_block_size(page) >= size);
36 mi_assert_internal(_mi_is_aligned(mi_page_slice_start(page), MI_PAGE_ALIGN));
37 mi_assert_internal(_mi_ptr_page(mi_page_start(page))==page);
38 }
39
40 // check the free list
41 mi_block_t* const block = page->free;
42 if mi_unlikely(block == NULL) {
43 return _mi_malloc_generic(theap, size, (zero ? 1 : 0), usable);
44 }
45 mi_assert_internal(block != NULL && _mi_ptr_page(block) == page);
46 if (usable != NULL) { *usable = mi_page_usable_block_size(page); };
47

Callers 2

_mi_page_malloc_zeroFunction · 0.85

Calls 6

mi_page_block_sizeFunction · 0.85
_mi_is_alignedFunction · 0.85
mi_page_slice_startFunction · 0.85
_mi_ptr_pageFunction · 0.85
mi_page_startFunction · 0.85
_mi_malloc_genericFunction · 0.85

Tested by

no test coverage detected