调用内核hlist编写的测试代码

这篇博客展示了如何在Linux内核中使用hlist数据结构。通过一系列的宏和函数,博主创建了一个包含100个元素的哈希表,并对其进行初始化、填充随机数据、打印及释放内存的操作。博客深入探讨了内核编程中的hlist用法及其在内存管理中的应用。
摘要由CSDN通过智能技术生成
最近在做linux内核编程,最深的一点感触是:算法的巧妙,犹如看一场高明杂技
真正的程序员那是键盘上灵动的舞者。
写面写的是一个调用内核的hlist测试代码。

/*
*
*how to program use  the hlist in kernel
*
*/

#include<linux/module.h> 
#include<linux/init.h> /* kind of macros */
#include<linux/kernel.h>
#include<linux/types.h>
#include<linux/list.h>
#include<linux/slab.h>


unsigned int len_hash = 100;
struct hlist_head* hash[100];

void get_random_bytes(void *buf,int nbytes);


/* define the data strc */
typedef struct _data_node{
    unsigned int  data;
    struct hlist_node node;
} data_node_strc;

/* init the hash-chain */
void init_hash(void)
{
  unsigned int i=0;
  for(i=0;i<len_hash;i++)
     {
        hash[i] = (struct hlist_head*)kmalloc(sizeof(struct hlis
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值