Skip to contentSkip to conversation

Windows NT page allocation

Qemu-devel Fabrice Bellard 2 participants 2 messages Nov 8, 2004

lore
Share & tools
lore
#0 lore raw

Hi,

Does someone know how to allocate a single 4 KB page of memory in Windows NT ?

Fabrice.

#1 lore raw
Quoted 1 line · Fabrice Bellard

Does someone know how to allocate a single 4 KB page of memory in Windows NT ?

In user mode you can allocate one page using
SYSTEM_INFO SystemInfo;
GetSystemInfo(&SystemInfo);
Address = VirtualAlloc(NULL, SystemInfo.dwPageSize, MEM_COMMIT |
MEM_RESERVE*, *PAGE_EXECUTE_READWRITE);
The problem is that the granuality of VirtualAlloc is 64Kb, so if you allocate 4Kb page this way you will end up with the rest 60Kb unusable (strictly speaking the memory can be still allocated using different mechanisms). It's possible to reserve more memory and then commit individual pages from the reserved region though. See http://msdn.microsoft.com/library/en-us/memory/base/reserving_and_committing_memory.asp for details.

Can you be more specific about the usage you intend? Maybe I would be able to suggest you better solution...

Regards,
Filip