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

Function os_malloc

common/sys/alloc.cpp:181–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179 }
180
181 void* os_malloc(size_t bytes, bool& hugepages)
182 {
183 if (bytes == 0) {
184 hugepages = false;
185 return nullptr;
186 }
187
188 /* try direct huge page allocation first */
189 if (isHugePageCandidate(bytes))
190 {
191 int flags = MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES;
192 char* ptr = (char*) VirtualAlloc(nullptr,bytes,flags,PAGE_READWRITE);
193 if (ptr != nullptr) {
194 hugepages = true;
195 return ptr;
196 }
197 }
198
199 /* fall back to 4k pages */
200 int flags = MEM_COMMIT | MEM_RESERVE;
201 char* ptr = (char*) VirtualAlloc(nullptr,bytes,flags,PAGE_READWRITE);
202 if (ptr == nullptr) throw std::bad_alloc();
203 hugepages = false;
204 return ptr;
205 }
206
207 size_t os_shrink(void* ptr, size_t bytesNew, size_t bytesOld, bool hugepages)
208 {

Callers 5

reallocMethod · 0.85
allocateMethod · 0.85
createMethod · 0.85
allocateMethod · 0.85
AllocationMethod · 0.85

Calls 2

isHugePageCandidateFunction · 0.85
os_adviseFunction · 0.85

Tested by

no test coverage detected