MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / mi_heap_malloc_aligned

Function mi_heap_malloc_aligned

3rd/mimalloc-2.0.9/src/alloc-aligned.c:148–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148mi_decl_nodiscard mi_decl_restrict void* mi_heap_malloc_aligned(mi_heap_t* heap, size_t size, size_t alignment) mi_attr_noexcept {
149 #if !MI_PADDING
150 // without padding, any small sized allocation is naturally aligned (see also `_mi_segment_page_start`)
151 if (!_mi_is_power_of_two(alignment)) return NULL;
152 if mi_likely(_mi_is_power_of_two(size) && size >= alignment && size <= MI_SMALL_SIZE_MAX)
153 #else
154 // with padding, we can only guarantee this for fixed alignments
155 if mi_likely((alignment == sizeof(void*) || (alignment == MI_MAX_ALIGN_SIZE && size > (MI_MAX_ALIGN_SIZE/2)))
156 && size <= MI_SMALL_SIZE_MAX)
157 #endif
158 {
159 // fast path for common alignment and size
160 return mi_heap_malloc_small(heap, size);
161 }
162 else {
163 return mi_heap_malloc_aligned_at(heap, size, alignment, 0);
164 }
165}
166
167// ------------------------------------------------------
168// Aligned Allocation

Callers 2

mainFunction · 0.85
mi_malloc_alignedFunction · 0.85

Calls 3

_mi_is_power_of_twoFunction · 0.85
mi_heap_malloc_smallFunction · 0.85

Tested by 1

mainFunction · 0.68