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

Function mi_padding_shrink

3rd/mimalloc-2.0.9/src/alloc.c:288–300  ·  view source on GitHub ↗

When a non-thread-local block is freed, it becomes part of the thread delayed free list that is freed later by the owning heap. If the exact usable size is too small to contain the pointer for the delayed list, then shrink the padding (by decreasing delta) so it will later not trigger an overflow error in `mi_free_block`.

Source from the content-addressed store, hash-verified

286// contain the pointer for the delayed list, then shrink the padding (by decreasing delta)
287// so it will later not trigger an overflow error in `mi_free_block`.
288static void mi_padding_shrink(const mi_page_t* page, const mi_block_t* block, const size_t min_size) {
289 size_t bsize;
290 size_t delta;
291 bool ok = mi_page_decode_padding(page, block, &delta, &bsize);
292 mi_assert_internal(ok);
293 if (!ok || (bsize - delta) >= min_size) return; // usually already enough space
294 mi_assert_internal(bsize >= min_size);
295 if (bsize < min_size) return; // should never happen
296 size_t new_delta = (bsize - min_size);
297 mi_assert_internal(new_delta < bsize);
298 mi_padding_t* padding = (mi_padding_t*)((uint8_t*)block + bsize);
299 padding->delta = (uint32_t)new_delta;
300}
301#else
302static void mi_check_padding(const mi_page_t* page, const mi_block_t* block) {
303 MI_UNUSED(page);

Callers 1

_mi_free_block_mtFunction · 0.85

Calls 1

mi_page_decode_paddingFunction · 0.85

Tested by

no test coverage detected