Block Alighment (memory)
Block alighment, in the context of sofware engineering/computer science, is putting data in memory at addresses that are a multiple of 4 (or whatever the word size is, x86’s word size is 4 bytes).
For example, if you have the following data
struct {
char a; // 1 byte
short b; // 2 bytes
int c; // 4 bytes
}
This struct should be laid in memory as follows:
address content
0 ───── char a
1
2
3
4 ───── short b
5 short b
6
7
8 ───── int c
9 int c
10 int c
11 int c
Notice, that regardless of the size of the data (1 byte, 2 byte, 4 bytes, etc), its address in memory always starts at a multiple of 4.
CPUs can fetch content at address of 4 multiples significantly faster than at other addresses.
For this reason, when you wanna save data to disk, or send it over the network, you “compress” it (make it non-block aligned) to save space, but when you load it back into memory again, you should block align it for speed.