Reputation: 3975
malloc() returns a memory suitably aligned for any in-built type. In cases where more specific alignment is required (like 16 or 32 bytes) it can be done at the application level. But this alignment is at the virtual memory level.
How is it guaranteed that the underlying physical memory is also at the same alignment ?
Upvotes: 3
Views: 665
Reputation: 782166
Virtual memory is implemented at the page level, so every VM page maps to a physical memory page when it's loaded into memory. So everything more finely grained than the page will also be aligned equivalently between virtual and physical memory.
Upvotes: 3