The main allocation function
| 125 | |
| 126 | // The main allocation function |
| 127 | extern inline void* _mi_heap_malloc_zero_ex(mi_heap_t* heap, size_t size, bool zero, size_t huge_alignment) mi_attr_noexcept { |
| 128 | if mi_likely(size <= MI_SMALL_SIZE_MAX) { |
| 129 | mi_assert_internal(huge_alignment == 0); |
| 130 | return mi_heap_malloc_small_zero(heap, size, zero); |
| 131 | } |
| 132 | else { |
| 133 | mi_assert(heap!=NULL); |
| 134 | mi_assert(heap->thread_id == 0 || heap->thread_id == _mi_thread_id()); // heaps are thread local |
| 135 | void* const p = _mi_malloc_generic(heap, size + MI_PADDING_SIZE, zero, huge_alignment); // note: size can overflow but it is detected in malloc_generic |
| 136 | mi_assert_internal(p == NULL || mi_usable_size(p) >= size); |
| 137 | #if MI_STAT>1 |
| 138 | if (p != NULL) { |
| 139 | if (!mi_heap_is_initialized(heap)) { heap = mi_get_default_heap(); } |
| 140 | mi_heap_stat_increase(heap, malloc, mi_usable_size(p)); |
| 141 | } |
| 142 | #endif |
| 143 | mi_track_malloc(p,size,zero); |
| 144 | return p; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | extern inline void* _mi_heap_malloc_zero(mi_heap_t* heap, size_t size, bool zero) mi_attr_noexcept { |
| 149 | return _mi_heap_malloc_zero_ex(heap, size, zero, 0); |
no test coverage detected