kmemdup
来源:互联网 发布:js触发事件 自动 编辑:程序博客网 时间:2024/05/17 23:47
在kernel中可以通过kmemdup将一种类型的数据赋值给另外同一个类型的数据。例如下例:就是要将thermal_zone_device_ops的数据赋值给ops。这个属于浅拷贝.struct thermal_zone_device_ops *ops;ops = kmemdup(&of_thermal_ops, sizeof(*ops), GFP_KERNEL);static struct thermal_zone_device_ops of_thermal_ops = {.get_mode = of_thermal_get_mode,.set_mode = of_thermal_set_mode,.get_trip_type = of_thermal_get_trip_type,.get_trip_temp = of_thermal_get_trip_temp,.set_trip_temp = of_thermal_set_trip_temp,.get_trip_hyst = of_thermal_get_trip_hyst,.set_trip_hyst = of_thermal_set_trip_hyst,.get_crit_temp = of_thermal_get_crit_temp,.bind = of_thermal_bind,.unbind = of_thermal_unbind,};我们看看kmemdup的源码void *kmemdup(const void *src, size_t len, gfp_t gfp){void *p;//先申请memoryp = kmalloc_track_caller(len, gfp);if (p) //如果memory申请成功,则通过memcpy赋值,所以这里很明确看出是浅拷贝。同时可以知道以后结构体复制可以通过memcpy直接进行memcpy(p, src, len);return p;}
阅读全文
0 0
- kmemdup
- mm/util.c 中的辅助函数kmemdup和kstrndup分析
- 一些好用的css和js
- ubuntu16.04上基于 VirtualEnv 安装tensorflow
- 【Android】实现开7分钟后关3分钟无限循环
- hdu 3613 manacher算法
- 微信公众平台开发 获取用户基本信息
- kmemdup
- [SDUT](2134)数据结构实验之栈四:括号匹配 ---栈
- 在Vue项目中使用easyScroll滚动条插件
- HTTPS握手过程与对称加密、非对称加密
- PullToRefreshBase添加头部视图
- shell脚本实例
- Linux下限制IP访问
- Map list的遍历问题
- tcp/ip-路由相关结构