|
[原创]链表之“结点即负载”
呵呵,我写这个东西的目的是为自己做个笔记,不是逗你们发笑,只有浮躁的人才会轻易嘲笑别人。给了一份大牛的代码,不知道才理解多少就评价是一份普通的代码,很多人看完都会赞写的妙,包括一些码龄将近10年的大牛。不理解方式②,我敢确定你根本没有静下心来看过这份代码,又或许你们是超大牛吧,因为好像对别人写的东西很不屑的样子。我能体会到你们的一点点好意,想劝我回头是岸、悬崖勒马,但你们连我表达的是什么意思都不理解,就开始攻击我的IQ,就相当于我站在楼顶看风景,你们俩在后面鬼哭狼嚎:不要跳楼,不要跳楼。呵呵,好玩 。 |
|
[原创]链表之“结点即负载”
场景:void *p1, *p2, *p3, ...,将这些指针的地址值用链表保存起来: 方法①: struct paddr { struct paddr *next; void *pvalue; }; struct paddr head, node1, node2, node3, ...; head.next = &node1, head.pvalue = NULL; node1.next = &node2, node1.pvalue = &p1; node2.next = &node3, node2.pvalue = &p2; node3.next = &node4, node3.pvalue = &p3; ... ... 方法②: void *head = &p1; p1 = &p2; p2 = &p3; p3 = &p4; ... ... 如果这样还看不明白,可以这样理解: struct paddr { struct paddr *next; }; 将p1,p2,p3,...分别看作node1,node2,node3,...,问题转换成需要将这些node的地址保存起来。茅塞顿开了没有?node的地址?每个node的地址不就是上个node的next值。 只是说还是有些抽象,以下算是证明吧: struct paddr head, node1, node2, node3, ...; p1 p2 p3 ... 既然你提到LIST_ENTRY,那麽应该能理解&node1->next == &node1吧? 还是跟你解释一下吧,next成员相对于paddr结构的偏移是0,所以它的地址与整个结构变量的地址相同。 以此类推:&node2->next == &node2; &node3->next == &node3; ... ... 目的不就是要保存这些指针的地址麽!从p1开始,保存到head结点中: head.next = &p1 (其中,&p1 == &node1 == &node1->next) 这里head.next不仅保存了p1指针的地址值,而且正好也指向了node1->next地址,即head与node1链在了一起; 将p2的地址保存到p1中: p1 = &p2 (其中,&p2 == &node2 == &node2->next) 这里p1不仅保存了p2指针的地址值,而且正好也指向了node2->next地址,即node1与node2链在了一起; ... ... 这样,不需要void *pvalue成员,也达到效果了。当然这种方法只能使用于特定的应用场景,这些指针最终肯定是要指向一些有具体意义的对象,而不是仅仅手拉手白站在链表里,比如一些指针的指向,需要等到某个计算结果出来以后才能明确,就可以先加到链表里“排队”。 还是建议看看这份代码:http://swtch.com/~rsc/regexp/nfa.c.txt 不要什么状况都还没搞清楚,就表示反对,做人要理性。 |
|
[原创]链表之“结点即负载”
没值, 还要指针干嘛? next的值正好就是我要的值啊,next不是指向下1个结点的地址麽,即下1个结点的地址正是哥想要的值,从整个链表看,所有结点的地址都是我要的值,即所有结点的next值以及链表头的值正好是我要的值。从应用场景看,如果我想把一组指针的地址(甚至是指针,知道指针地址还得不到指针?)保存起来,而且指针的个数事先无法预计,且随时都可能添加、删除,就可以用这种方式。 |
|
[原创]链表之“结点即负载”
① 要访问load的话,需要先找到节点,再取load地址,多了一个过程; 如果可以随机访问,那不就是数组了? ② 取load时,还得判断load值是否为空,这样,即增加代码书写量,还增加cpu运算量。 值为空就是链表尾巴了啊,你访问单向链表难道都不判断是否已到达尾部的吗? 建议这位兄弟看看这个代码,是1个简单的正则表达式功能,不到400行代码,保证你会遇到和我一样的疑惑,顺便看看我们的理解是否一致:http://swtch.com/~rsc/regexp/nfa.c.txt。 |
|
[求助]一无所知的小白能否在这里破蛹成蝶
我工作大概有2年了,这些是我感觉比较重要的几点: ① 不要对什么都感兴趣,不要见什么爱什么,各个方面都有些了解是很有帮助的,但不能同时拼命钻几个地方,不要认为精通web可以拿网站、写木马很酷、搞破解也很酷,然后什么都想搞一搞,这样是不对的,这条最重要,如果是外星人,可以不听; ② 编程重在思想,虽然我不一个精通很多编程语言的人,但我很多语言都学过,最后坚持用的只有c,每种语言都有他精华的部分,但对于初学者,那不是最重要的,最重要的是掌握编程思想,然后等到一定的程度,你自然有冲动去学习其他的语言,有冲动、有基础,效率才高; ③ 当你学习一种新的技术时,可能会遇到很多难点,过于抽象,可能你把一篇文章或者一本书的某几个章节翻了好多遍,还是不理解,那就可能要先放一放了,这可能有两个主要原因:你有个强烈的惯性思想在干扰你,你需要放一放让大脑冷却一下;你还缺少一些知识点,所以要放一放,等这些知识点到位了,你再回头理解这个难题,你可能会对当时理解不了这个问题感到很奇怪; ④ 多用google,百度,多请教别人,多思考,不要浪费时间,另外要谦虚。 |
|
[转帖]准备转型
我现在很迷茫,想开始学汇编,之前有点基础 。 |
|
[讨论]发一个linux平台下的hook程序
0_0 ~ |
|
[结贴][求助]一个超级奇怪的C语言语法,求解
晕, 前面都已经有答案了。 |
|
[结贴][求助]一个超级奇怪的C语言语法,求解
LZ让我开眼界了,我在linux环境写了个代码帮你试了一下: #include <stdio.h> struct test { char ch; int i; }; void fun(t) struct test *t; // 这里 void fun(struct test *t),它是将t的类型"拿到"括号外面声明了 { t->ch = 'b'; t->i = 2; } int main() { struct test t = { 'a', 1 }; printf("t.ch: %c, t.i: %d\n", t.ch, t.i); fun(&t); printf("t.ch: %c, t.i: %d\n", t.ch, t.i); return 0; } |
|
[求助]是系统崩溃了还是我崩溃了?
既然是崩溃了, 那肯定是崩溃了。 |
|
[原创]感觉对逆向和病毒完全失去兴趣了
人的情绪总会有波动的, 睡一觉就好了。 |
|
[讨论]说下google开源项目那点破事......
google精神,激励你不断去google 0_0。 |
|
[原创]科普NDIS封包过滤
你说谎, 你不是小菜 ! |
|
[转帖]linux文件权限知多少
http://hi.baidu.com/mcaeebbkarjknte/item/f25945493c2388ab60d7b95c 如果紧张还赖着内存不放不好吧,这里说是为了大程序下次启动时能快点,也说到防删的作用了。 |
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值