PS:内存对齐为 &运算,需要转化为二进制来计算。可使用二进制计算机计算
//C 层面的函数 word_align:字节对齐
static inline uint32_t word_align(uint32_t x) {
return (x + WORD_MASK) & ~WORD_MASK;
}
//解析:内存对齐的算法 &运算 (此处结果为8的倍数,或者16的倍数,或...)
static inline uint32_t word_align(uint32_t x) {// x:8, define WORD_MASK 7UL
// 7+8 = 15
// 0000 0111 -> 7
// 0000 1000 -> 8
// 0000 1111 -> 15
// &
// 1111 1000 -> ~7 ~非运算,二进制中,0变1,1变0
// 0000 1000 -> 8
return (x + WORD_MASK) & ~WORD_MASK;
}