The parameters for this function must be aligned on a 32-bit boundary; otherwise, the function will behave unpredictably on multiprocessor x86 systems and any non-x86 systems. See _aligned_malloc.
mmozeiko
VirtualAlloc will return memory that begins on page boundary (typically 4KB).
Pseudonym73
Can someone call GetSystemInfo() and check please?
mmozeiko
4096 on Windows 8.1 64-bit (16GB total memory, if that changes anything).
And also 4096 on Windows XP 32-bit (under VirtualBox).
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <stdint.h> #include <stdlib.h> #include <stdio.h> #include <windows.h> int main() { for (int i=0; i<100; i++) { uint64_t addr = (uint64_t)VirtualAlloc(NULL, 123123*(rand()%100+1), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); printf("0x%016llx %% 64k = %i\n", addr, addr % (64*1024)); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 0x00000000025e0000 % 64k = 0 0x0000000005740000 % 64k = 0 0x000000000a720000 % 64k = 0 0x00000000020f0000 % 64k = 0 0x000000000d040000 % 64k = 0 0x0000000012280000 % 64k = 0 0x0000000013fe0000 % 64k = 0 0x0000000019cb0000 % 64k = 0 0x000000001e200000 % 64k = 0 0x0000000022c00000 % 64k = 0 0x0000000027860000 % 64k = 0 0x0000000027f70000 % 64k = 0 0x000000002b580000 % 64k = 0 0x00000000315d0000 % 64k = 0 0x00000000336c0000 % 64k = 0 0x0000000037f90000 % 64k = 0 ... |
Raymond Chen
You don't want to introduce gratuitous differences between architectures because it makes porting code between them harder.