Question

Will the memory block returned by VirtualAlloc always be aligned with the page size? In other words, will the modulus always be zero of the return value from VirtualAlloc and the page size?

Was it helpful?

Solution

Well, yes.

After all, you call VirtualAlloc to allocate some memory pages. You cannot allocate only 1 byte without receiving a whole page, so it makes sense that you will receive a buffer aligned with the page size.

OTHER TIPS

From the MSDN documentation for VirtualAlloc:

If the memory is already reserved and is being committed, the address is rounded down to the next page boundary.

So the answer is yes, if you are committing the memory and not just reserving it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top