Recently when i was going through a code, I found #pragma DATA_ALIGN(var, 4*1024). var is a structure variable that is around 20k long. I searched for this in the internet and could not find anything useful. Can anyone provide me links or shed some light on this?
Recently when i was going through a code, I found #pragma DATA_ALIGN(var, 4*1024). var
Share
This means that
varstructure will be page-aligned (standard page size in most computer architectures is 4K=4096 bytes), i.e. it will be stored at location with address dividable by 4096. Such approach improves performance, since the OS acquires the data in chunks equal to page size from disk (i.e.paged memory), by doing what’s calledpage fault. Eachpage faultis an additional work for processor and I/O system. Minimizing number ofpage faultsis a strong mean to improve performance. If the data isn’t page-aligned, access to it might require an additionalpage fault, while only a part of the brought data is needed.Edit:
Although in most cases aligning to 4K is due to memory management, there might be other reasons for alignment, mostly HW restrictions – as was correctly pointed out by @CodePainters.