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

Function _mi_arena_alloc_aligned

3rd/mimalloc-2.0.9/src/arena.c:248–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

246}
247
248void* _mi_arena_alloc_aligned(size_t size, size_t alignment, size_t align_offset, bool* commit, bool* large, bool* is_pinned, bool* is_zero,
249 mi_arena_id_t req_arena_id, size_t* memid, mi_os_tld_t* tld)
250{
251 mi_assert_internal(commit != NULL && is_pinned != NULL && is_zero != NULL && memid != NULL && tld != NULL);
252 mi_assert_internal(size > 0);
253 *memid = MI_MEMID_OS;
254 *is_zero = false;
255 *is_pinned = false;
256
257 bool default_large = false;
258 if (large == NULL) large = &default_large; // ensure `large != NULL`
259 const int numa_node = _mi_os_numa_node(tld); // current numa node
260
261 // try to allocate in an arena if the alignment is small enough and the object is not too small (as for heap meta data)
262 if (size >= MI_ARENA_MIN_OBJ_SIZE && alignment <= MI_SEGMENT_ALIGN && align_offset == 0) {
263 void* p = mi_arena_allocate(numa_node, size, alignment, commit, large, is_pinned, is_zero, req_arena_id, memid, tld);
264 if (p != NULL) return p;
265 }
266
267 // finally, fall back to the OS
268 if (mi_option_is_enabled(mi_option_limit_os_alloc) || req_arena_id != _mi_arena_id_none()) {
269 errno = ENOMEM;
270 return NULL;
271 }
272 *is_zero = true;
273 *memid = MI_MEMID_OS;
274 void* p = _mi_os_alloc_aligned_offset(size, alignment, align_offset, *commit, large, tld->stats);
275 if (p != NULL) { *is_pinned = *large; }
276 return p;
277}
278
279void* _mi_arena_alloc(size_t size, bool* commit, bool* large, bool* is_pinned, bool* is_zero, mi_arena_id_t req_arena_id, size_t* memid, mi_os_tld_t* tld)
280{

Callers 4

mi_region_try_alloc_osFunction · 0.85
_mi_mem_alloc_alignedFunction · 0.85
mi_segment_os_allocFunction · 0.85
_mi_arena_allocFunction · 0.85

Calls 5

_mi_os_numa_nodeFunction · 0.85
mi_arena_allocateFunction · 0.85
mi_option_is_enabledFunction · 0.85
_mi_arena_id_noneFunction · 0.85

Tested by

no test coverage detected