VirtualAlloc alignment
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?
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.
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.
精彩评论