当你使用container_of宏? [英] When do you use container_of macro?

查看:327
本文介绍了当你使用container_of宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道宏做什么。

在许多内核级codeS,它经常被用于遍历链接列表

In many kernel level codes, it is often used to traverse linked-list.

我要找到其他有用的情况。结果
当你使用container_of或 CONTAINING_RECORD 宏碁结果
如果是宏非常有用吗?

I want to find other useful cases.
When do you use container_of or CONTAINING_RECORD macro?
When is the macro extremely useful?

推荐答案

container_of ,可以忽略指向父结构来简化你的数据结构。

container_of allows you to simplify your data structures by omitting pointers to parent structures.

它链表实现中使用,使得该列表节点可以是任何结构的元件,任何人都可以找到与母体结构而不围绕一个明确的指针携带

It's used within the linked list implementation so that the list node can be an element of any structure, and anyone can find the parent structure without carrying around an explicit pointer.

另一个例子是结构work_struct 。工作队列功函数接收一个work_struct作为一个参数,它曾经有一个通用的数据有效载荷。这个数据值是删除,使结构更小,功函数可以调用 container_of 找到其父结构。

Another example is struct work_struct. A workqueue work function receives a work_struct as an argument, and it used to have a generic "data" payload. This data value was removed, making the structure smaller, as the work function can call container_of to find its parent structure.

这篇关于当你使用container_of宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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