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

Function mi_win_virtual_allocx

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

Source from the content-addressed store, hash-verified

399#define MEM_COMMIT_RESERVE (MEM_COMMIT|MEM_RESERVE)
400
401static void* mi_win_virtual_allocx(void* addr, size_t size, size_t try_alignment, DWORD flags) {
402#if (MI_INTPTR_SIZE >= 8)
403 // on 64-bit systems, try to use the virtual address area after 2TiB for 4MiB aligned allocations
404 if (addr == NULL) {
405 void* hint = mi_os_get_aligned_hint(try_alignment,size);
406 if (hint != NULL) {
407 void* p = VirtualAlloc(hint, size, flags, PAGE_READWRITE);
408 if (p != NULL) return p;
409 _mi_verbose_message("warning: unable to allocate hinted aligned OS memory (%zu bytes, error code: 0x%x, address: %p, alignment: %zu, flags: 0x%x)\n", size, GetLastError(), hint, try_alignment, flags);
410 // fall through on error
411 }
412 }
413#endif
414 // on modern Windows try use VirtualAlloc2 for aligned allocation
415 if (try_alignment > 1 && (try_alignment % _mi_os_page_size()) == 0 && pVirtualAlloc2 != NULL) {
416 MI_MEM_ADDRESS_REQUIREMENTS reqs = { 0, 0, 0 };
417 reqs.Alignment = try_alignment;
418 MI_MEM_EXTENDED_PARAMETER param = { {0, 0}, {0} };
419 param.Type.Type = MiMemExtendedParameterAddressRequirements;
420 param.Arg.Pointer = &reqs;
421 void* p = (*pVirtualAlloc2)(GetCurrentProcess(), addr, size, flags, PAGE_READWRITE, &param, 1);
422 if (p != NULL) return p;
423 _mi_warning_message("unable to allocate aligned OS memory (%zu bytes, error code: 0x%x, address: %p, alignment: %zu, flags: 0x%x)\n", size, GetLastError(), addr, try_alignment, flags);
424 // fall through on error
425 }
426 // last resort
427 return VirtualAlloc(addr, size, flags, PAGE_READWRITE);
428}
429
430static void* mi_win_virtual_alloc(void* addr, size_t size, size_t try_alignment, DWORD flags, bool large_only, bool allow_large, bool* is_large) {
431 mi_assert_internal(!(large_only && !allow_large));

Callers 1

mi_win_virtual_allocFunction · 0.85

Calls 4

mi_os_get_aligned_hintFunction · 0.85
_mi_verbose_messageFunction · 0.85
_mi_os_page_sizeFunction · 0.85
_mi_warning_messageFunction · 0.85

Tested by

no test coverage detected