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

Function mi_segment_reclaim_or_alloc

3rd/mimalloc-2.0.9/src/segment.c:1463–1482  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1461----------------------------------------------------------- */
1462
1463static mi_segment_t* mi_segment_reclaim_or_alloc(mi_heap_t* heap, size_t needed_slices, size_t block_size, mi_segments_tld_t* tld, mi_os_tld_t* os_tld)
1464{
1465 mi_assert_internal(block_size < MI_HUGE_BLOCK_SIZE);
1466 mi_assert_internal(block_size <= MI_LARGE_OBJ_SIZE_MAX);
1467
1468 // 1. try to reclaim an abandoned segment
1469 bool reclaimed;
1470 mi_segment_t* segment = mi_segment_try_reclaim(heap, needed_slices, block_size, &reclaimed, tld);
1471 if (reclaimed) {
1472 // reclaimed the right page right into the heap
1473 mi_assert_internal(segment != NULL);
1474 return NULL; // pretend out-of-memory as the page will be in the page queue of the heap with available blocks
1475 }
1476 else if (segment != NULL) {
1477 // reclaimed a segment with a large enough empty span in it
1478 return segment;
1479 }
1480 // 2. otherwise allocate a fresh segment
1481 return mi_segment_alloc(0, 0, heap->arena_id, tld, os_tld, NULL);
1482}
1483
1484
1485/* -----------------------------------------------------------

Callers 1

mi_segments_page_allocFunction · 0.85

Calls 2

mi_segment_try_reclaimFunction · 0.85
mi_segment_allocFunction · 0.85

Tested by

no test coverage detected