Tagged 初始化是否允许结构成员重新排序?
Is it true that Tagged initialization allows the reordering of structure members?
我正在阅读 "Linux Device Driver" 第三版。
摘录:
The scull device driver implements only the most important device
methods. Its file_operations structure is initialized as follows:
struct file_operations scull_fops = {
.owner = THIS_MODULE,
.llseek = scull_llseek,
.read = scull_read,
.write = scull_write,
.ioctl = scull_ioctl,
.open = scull_open,
.release = scull_release,
};
This
declaration uses the standard C tagged structure initialization
syntax. This syntax is preferred because it makes drivers more
portable across changes in the definitions of the structures and,
arguably, makes the code more compact and readable. Tagged
initialization allows the reordering of structure members; in some
cases, substantial performance improvements have been realized by
placing pointers to frequently accessed members in the same hardware
cache line.
我可能看错了。它们是否意味着对象内存中的最终布局将不同于初始结构定义?因此不可移植?我看不到建议的可行实施。有人可以向我解释最后一段中的建议吗?他们是否暗示函数在内存中的最终位置会受到影响并相互靠近?因此更有可能在同一个缓存行中。
对象在内存中的最终布局完全依赖于linux/fs.h
头文件中的struct file_operations
定义。
他们的意思是这个定义可以出于性能原因改变order,并且这种改变不会破坏任何使用tagged初始化的驱动程序其成员(与成员的未命名初始化相反按顺序它们出现在结构的定义中)。
此外,除了重新排序结构成员外,还可以 添加 新成员和 删除 未使用的成员,而不会破坏现有的驱动程序。而这实际上发生在内核中。
我正在阅读 "Linux Device Driver" 第三版。
摘录:
The scull device driver implements only the most important device methods. Its file_operations structure is initialized as follows:
struct file_operations scull_fops = { .owner = THIS_MODULE, .llseek = scull_llseek, .read = scull_read, .write = scull_write, .ioctl = scull_ioctl, .open = scull_open, .release = scull_release, };
This declaration uses the standard C tagged structure initialization syntax. This syntax is preferred because it makes drivers more portable across changes in the definitions of the structures and, arguably, makes the code more compact and readable. Tagged initialization allows the reordering of structure members; in some cases, substantial performance improvements have been realized by placing pointers to frequently accessed members in the same hardware cache line.
我可能看错了。它们是否意味着对象内存中的最终布局将不同于初始结构定义?因此不可移植?我看不到建议的可行实施。有人可以向我解释最后一段中的建议吗?他们是否暗示函数在内存中的最终位置会受到影响并相互靠近?因此更有可能在同一个缓存行中。
对象在内存中的最终布局完全依赖于linux/fs.h
头文件中的struct file_operations
定义。
他们的意思是这个定义可以出于性能原因改变order,并且这种改变不会破坏任何使用tagged初始化的驱动程序其成员(与成员的未命名初始化相反按顺序它们出现在结构的定义中)。
此外,除了重新排序结构成员外,还可以 添加 新成员和 删除 未使用的成员,而不会破坏现有的驱动程序。而这实际上发生在内核中。