MCPcopy Create free account
hub / github.com/RenderKit/embree / os_shrink

Function os_shrink

common/sys/alloc.cpp:207–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205 }
206
207 size_t os_shrink(void* ptr, size_t bytesNew, size_t bytesOld, bool hugepages)
208 {
209 if (hugepages) // decommitting huge pages seems not to work under Windows
210 return bytesOld;
211
212 const size_t pageSize = hugepages ? PAGE_SIZE_2M : PAGE_SIZE_4K;
213 bytesNew = (bytesNew+pageSize-1) & ~(pageSize-1);
214 bytesOld = (bytesOld+pageSize-1) & ~(pageSize-1);
215 if (bytesNew >= bytesOld)
216 return bytesOld;
217
218 if (!VirtualFree((char*)ptr+bytesNew,bytesOld-bytesNew,MEM_DECOMMIT))
219 throw std::bad_alloc();
220
221 return bytesNew;
222 }
223
224 void os_free(void* ptr, size_t bytes, bool hugepages)
225 {

Callers 1

shrinkMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected