链接器 – 什么是二进制格式的“对齐”字段?为什么需要它?

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

Windows PE文件格式的情况下,它们将它带到下一级别,Sections有两个对齐值,一个在磁盘文件中,另一个在内存中. PE文件头指定这两个值.

我不明白这种对齐方式.我们需要什么?怎么&在哪里使用?同样,我不知道二进制文件格式上下文中的对齐方式,但为什么我们需要它呢?

最佳答案 那么,对齐通常会扩展某些值的存储大小以占用一些“圆形”空间,如32,64,128位等.

如果我们谈论二进制格式,可以这样做以优化格式处理.当您读/写一些“圆形”数据长度部分时,读/写操作会更快.

我找到了一本适合你的阅读材料,用现在我想出的更好的词语表达:

Data structure alignment

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.

点赞