什么是“对准"?二进制格式的字段?为什么需要它? [英] What is "Alignment" field in binary formats? Why is it needed?

查看:76
本文介绍了什么是“对准"?二进制格式的字段?为什么需要它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ELF 文件格式中,我们在Segment Header Table aka Program Header Table中有一个 Alignment 字段.

In ELF file format we have an Alignment field in Segment Header Table aka Program Header Table.

对于Windows PE文件格式,它们将其带到了更高的层次.节具有两个对齐值,一个在磁盘文件中,另一个在内存中. PE文件头指定了这两个值.

In case of Windows PE file format they take it to next level the Sections have two alignment values, one within the disk file and the other in memory. The PE file header specifies both of these values.

我对这种对齐方式一无所知.我们需要什么?如何及在哪里使用?同样,我不知道二进制文件格式上下文中的对齐方式是什么,但是为什么需要它?

I didn't understand a thing about this alignment. What do we need it for? How & Where is it used? Again, I don't know what is alignment in binary file format context but why do we need it?

推荐答案

好吧,对齐通常会扩展某个值的存储大小以占据一些舍入"空间,例如32、64、128位等.

Well, alignment is usually stretching the storage size of some value to occupy some "round" space, like 32, 64, 128 bit etc.

如果我们谈论的是二进制格式,可以这样做是为了优化格式处理.当您读/写一些舍入"数据长度部分时,读/写操作会更快.

If we're talking about binary formats, it may be done in order to optimize format processing. Read/write operations can be quicker when you read/write some "round" data length portions.

我找到了适合您的阅读材料,现在我可以用更好的语言表达出来:

I found a reading for you, formulated in better words I can come up with right now:

数据结构对齐

数据结构对齐是在计算机内存中排列和访问数据的方式.它包含两个独立但相关的问题:数据对齐数据结构填充.当现代计算机读取或写入内存地址时,它将以字大小的块(例如,在32位系统上为4字节的块)来执行此操作. 数据对齐意味着将数据放在等于字长的倍数的内存偏移处,这由于CPU处理内存的方式而提高了系统的性能.为了对齐数据,可能有必要在最后一个数据结构的末尾与下一个数据结构的末尾(即数据结构填充)之间插入一些无意义的字节.

Data structure alignment is the way data is arranged and accessed in computer memory. It consists of two separate but related issues: data alignment and data structure padding. When a modern computer reads from or writes to a memory address, it will do this in word sized chunks (e.g. 4 byte chunks on a 32-bit system). Data alignment means putting the data at a memory offset equal to some multiple of the word size, which increases the system's performance due to the way the CPU handles memory. To align the data, it may be necessary to insert some meaningless bytes between the end of the last data structure and the start of the next, which is data structure padding.

这篇关于什么是“对准"?二进制格式的字段?为什么需要它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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