Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual memory and alignment - how do they factor together?

I think I understand memory alignment, but what confuses me is that the address of a pointer on some systems is going to be in virtual memory, right? So most of the checking/ensuring of alignment I have seen seem to just use the pointer address. Is it not possible that the physical memory address will not be aligned? Isn't that problematic for things like SSE?

like image 681
Doug Moscrop Avatar asked Nov 19 '11 02:11

Doug Moscrop


1 Answers

The physical address will be aligned because virtual memory only maps aligned pages to physical memory (and the pages are typically 4KB).

So unless you need alignment > page size, the physical memory will be aligned as per your requirements.

In the specific case of SSE, everything works fine because you only need 16 byte alignment.

like image 136
Anthony Blake Avatar answered Nov 15 '22 19:11

Anthony Blake