自然对齐的内存地址 [英] Naturally aligned memory address

查看:142
本文介绍了自然对齐的内存地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从现有的64位值中提取一个存储器地址,和这个地址指向一个4K阵列,起始值是:

I need to extract a memory address from within an existing 64-bit value, and this address points to a 4K array, the starting value is:

0x000000030c486000

我所需要的地址存储位51:12之内,所以我提取使用这些位:

The address I need is stored within bits 51:12, so I extract those bits using:

address = start >> 12 & 0x0000007FFFFFFFFF

这给我留下的地址:

0x000000000030c486

不过,我在读状态下的文档存储在地址数组的大小为4KB,自然对齐。

However, the documentation I'm reading states that the array stored at the address is 4KB in size, and naturally aligned.

我是一个有点困惑在什么实际自然对齐的意思。我知道与页对齐的东西地址通常与'000'(虽然我可能是错上)结束。

I'm a little bit confused over what naturally aligned actually means. I know with page aligned stuff the address normally ends with '000' (although I could be wrong on that).

我假定作为从起点值而采取的地址是唯一的40位长,我需要执行额外bitshifting操作到比特安排,使得它们可以PTED任何进一步正确间$ P $

I'm assuming that as the address taken from the starting value is only 40 bits long, I need to perform an additional bitshifting operation to arrange the bits so that they can be correctly interpreted any further.

如果任何人都可以做此提供一些建议,我倒是AP preciate它。

If anyone could offer some advice on doing this, I'd appreciate it.

感谢

推荐答案

一般情况下,自然对齐是指任何项目被对准到至少其自身的大小的倍数。例如,一个4字节的对象对齐这是4的倍数的地址,一个8字节的对象对齐这是8的倍数的地址等。

Normally, "naturally aligned" means that any item is aligned to at least a multiple of its own size. For example, a 4-byte object is aligned to an address that's a multiple of 4, an 8-byte object is aligned to an address that's a multiple of 8, etc.

有关的阵列,则通常不看整个阵列的大小,但在阵列的元件的尺寸。

For an array, you don't normally look at the size of the whole array, but at the size of an element of the array.

同样,对于结构联盟,你通常看最大元素的大小。

Likewise, for a struct or union, you normally look at the size of the largest element.

这篇关于自然对齐的内存地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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