虚拟内存和对齐 - 他们如何一起考虑? [英] Virtual memory and alignment - how do they factor together?

查看:210
本文介绍了虚拟内存和对齐 - 他们如何一起考虑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我理解内存对齐,但令我困惑的是,一些系统上的指针地址将在虚拟内存中,对吧?所以大多数检查/确保对齐我已经看到似乎只是使用指针地址。物理内存地址不可能不对齐吗?

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?

推荐答案

物理地址将被对齐,因为虚拟内存只将对齐页面映射到物理

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.

在SSE的特定情况下,一切正常,因为你只需要16字节对齐。

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

这篇关于虚拟内存和对齐 - 他们如何一起考虑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆