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

Function _mi_os_shrink

3rd/mimalloc-2.0.9/src/os.c:1129–1147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1127
1128
1129bool _mi_os_shrink(void* p, size_t oldsize, size_t newsize, mi_stats_t* stats) {
1130 // page align conservatively within the range
1131 mi_assert_internal(oldsize > newsize && p != NULL);
1132 if (oldsize < newsize || p == NULL) return false;
1133 if (oldsize == newsize) return true;
1134
1135 // oldsize and newsize should be page aligned or we cannot shrink precisely
1136 void* addr = (uint8_t*)p + newsize;
1137 size_t size = 0;
1138 void* start = mi_os_page_align_area_conservative(addr, oldsize - newsize, &size);
1139 if (size == 0 || start != addr) return false;
1140
1141#ifdef _WIN32
1142 // we cannot shrink on windows, but we can decommit
1143 return _mi_os_decommit(start, size, stats);
1144#else
1145 return mi_os_mem_free(start, size, true, stats);
1146#endif
1147}
1148
1149
1150/* ----------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 3

_mi_os_decommitFunction · 0.85
mi_os_mem_freeFunction · 0.85

Tested by

no test coverage detected