开发者

VirtualAlloc alignment

开发者 https://www.devze.com 2022-12-19 12:59 出处:网络
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 si

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号