第十一章:内核的数据处理
2012-03-30 14:33
141 查看
在编译时使用-Wall –Wstrict-prototypes选项编译可以防止大多数的代码缺陷。
使用标准C语言类型
内核中的普通内存地址通常是unsigned long ,因为:至少在当前linux支持的所有平台上,指针和long整型的大小是一样的。
为数据项分配确定的空间大小
在<asm/types.h>中定义若干类型:u8, u16, u32, u64。
使用新的编译器可以定义如下类型等等:uint8_t, uint32_t。
其他有关移植性的问题
页分配常见代码:假设需要16KB空间来存储临时数据,则分配页的代码是
#include <asm/pages.h>
int order = get_order(16*1024);
buf = get_free_pages(FGP_KERNEL, order);
传给order的值必须是2的幂。
链表
相关类型以及API
struct list_head{struct list_head *next, *prev;};
初始化
sturct list_head todo_list;
INIT_LIST_HEAD(&todo_list);
也可以这样初始化:
LIST_HEAD(todo_list);
API:
list_add(struct list_head *new, struct list_head *head);
list_add_tail(struct list_head *new, struct list_head *head);
list_del(struct list_head *entry);
list_del_init(struct list_head *entry);
list_empty(struct list_head *head);
list_entry(entry, type, name);
list_move(struct list_head *entry, struct list_head *head);
list_move_tail(struct list_head *entry, struct list_head *head);
list_splice(struct list_head *list, struct list_head *head);
使用标准C语言类型
内核中的普通内存地址通常是unsigned long ,因为:至少在当前linux支持的所有平台上,指针和long整型的大小是一样的。
为数据项分配确定的空间大小
在<asm/types.h>中定义若干类型:u8, u16, u32, u64。
使用新的编译器可以定义如下类型等等:uint8_t, uint32_t。
其他有关移植性的问题
页分配常见代码:假设需要16KB空间来存储临时数据,则分配页的代码是
#include <asm/pages.h>
int order = get_order(16*1024);
buf = get_free_pages(FGP_KERNEL, order);
传给order的值必须是2的幂。
链表
相关类型以及API
struct list_head{struct list_head *next, *prev;};
初始化
sturct list_head todo_list;
INIT_LIST_HEAD(&todo_list);
也可以这样初始化:
LIST_HEAD(todo_list);
API:
list_add(struct list_head *new, struct list_head *head);
list_add_tail(struct list_head *new, struct list_head *head);
list_del(struct list_head *entry);
list_del_init(struct list_head *entry);
list_empty(struct list_head *head);
list_entry(entry, type, name);
list_move(struct list_head *entry, struct list_head *head);
list_move_tail(struct list_head *entry, struct list_head *head);
list_splice(struct list_head *list, struct list_head *head);
相关文章推荐
- 【Linux 驱动】第十一章 内核的数据类型
- 套接字的内核实现原理以及对数据的处理流程简述
- c#网络通信框架networkcomms内核解析之六 处理接收到的二进制数据
- 《Linux Device Drivers》第十一章 内核的数据类型——note
- c#网络通信框架networkcomms内核解析之六 处理接收到的二进制数据
- Linux2.4系列内核对于网络数据的处理
- 第十一章 内核的数据类型
- 基于linux3.0内核fl2440开发板下的gps数据采集与处理
- 人工智能:python 实现 第十一章,使用Pandas处理时间序列数据
- 第十一章--内核的数据类型
- 第十一章 内核数据类型
- 大数据处理 linux内核数据
- PHP处理客户端数据请求
- postgresql备份恢复之pg_dump大数据处理
- Mybatis使用数据表&实体类属性不一致时候如何处理
- 云计算环境下的大规模图数据处理技术
- 如何处理大数据
- iOS项目开发中,对后台返回数据为<null>时候的处理,避免取值产生程序崩溃问题
- Unity (C#) 使用 LitJson 处理 JSON 数据
- 日处理20亿数据,实时用户行为服务系统架构实践