logoalt Hacker News

gblarggtoday at 8:33 AM1 replyview on HN

If you don't align the array to a 4K boundary in memory, fitting within a page isn't as big of an optimization win.


Replies

account42today at 9:28 AM

If the array is dynamically allocated on its own, you will likely get a whole page from any decent allocator. If it is statically allocated the compiler can at least theoretically optimize the alignment. If its allocated as part of a larger struct then yes its up to you.

Even if it is not aligned, an unaligned 8K array would be spread to three pages which is still worse than two.