-
Notifications
You must be signed in to change notification settings - Fork 1
/
朝花夕拾.html
83 lines (83 loc) · 4.16 KB
/
朝花夕拾.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html><html><head><meta charset="utf-8"><link rel="stylesheet" type="text/css" href="./css/github_new.css"><link rel="shortcut icon" href="favicon.png" type="image/x-icon"><!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-160306868-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-160306868-1');
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5809313774160994"
crossorigin="anonymous"></script>
<title>朝花夕拾</title></head><body><h2>一. c宏</h2>
<ol>
<li>
<p><code class="notranslate">do{}while(0)</code> 宏的用处?</p>
<p>避免调用者出现使用错误,保证程序执行的一致性。<br>
例如:</p>
<div class="highlight highlight-source-c"><pre class="notranslate"><span class="pl-k">#define</span> <span class="pl-en">FOO</span>() foo1();foo2();</pre></div>
<p>调用代码:</p>
<div class="highlight highlight-source-c"><pre class="notranslate"><span class="pl-k">if</span> (<span class="pl-s1">a</span> <span class="pl-c1">></span> <span class="pl-c1">0</span>)
<span class="pl-en">FOO</span>();</pre></div>
<p>会被扩展成:</p>
<div class="highlight highlight-source-c"><pre class="notranslate"><span class="pl-k">if</span> (<span class="pl-s1">a</span> <span class="pl-c1">></span> <span class="pl-c1">0</span>)
<span class="pl-en">foo1</span>();<span class="pl-en">foo2</span>();</pre></div>
<p>这时就产生了一个问题,若是<code class="notranslate">a <= 0</code>,<code class="notranslate">foo2()</code>仍然会被调用。<br>
正确的写法:</p>
<div class="highlight highlight-source-c"><pre class="notranslate"><span class="pl-k">#define</span> <span class="pl-en">FOO</span>() \
do{ \
foo1(); \
foo2(); \
}while(0)</pre></div>
</li>
</ol>
<h2>二. 计算机二三事</h2>
<ol>
<li>
<p>栈和堆的区别</p>
<ul>
<li>栈的结构是先进后出,永远操作的是栈顶</li>
<li>栈中的数据必须已知且大小固定(如c语言的数组)</li>
<li>堆是缺乏组织的,当向堆中放入数据,操作系统会去寻找到一块足够大的空间,标记为已使用,并返回一个指向这块空间的指针</li>
</ul>
<p>操作栈空间是比堆速度快的,因为使用堆你需要先寻找到一块足够大的空间(<code class="notranslate">malloc</code>),而且使用的内存并不是连续的(如动态链表),需要在内存中跳来跳去,这些操作都会降低性能。<br>
还有很多原因,如cpu对栈有直接支持(<code class="notranslate">push</code>, <code class="notranslate">pop</code>);栈内存由操作系统管理,而堆内存由用户程序管理。</p>
</li>
<li>
<p>指针</p>
<blockquote>
<p>In computer science, a pointer is a programming language object that stores a memory address. --wikipedia</p>
</blockquote>
<p>在计算机科学中,指针就是存储了一个内存地址的编程语言对象。</p>
</li>
<li>
<p>引用</p>
<p>以 java 为例:</p>
<blockquote>
<p>A reference is an address that indicates where an object's variables and methods are stored.</p>
</blockquote>
<p>引用是一个指向了对象的方法和变量存储位置的地址。</p>
</li>
</ol>
<h2>三. linux命令</h2>
<ol>
<li>
<p>删除当前目录除某文件外的所有文件</p>
<div class="highlight highlight-source-shell"><pre class="notranslate">ls <span class="pl-k">|</span> grep -v except_filename <span class="pl-k">|</span> xargs rm -rf</pre></div>
</li>
<li>
<p>更新所有的module</p>
<pre class="notranslate"><code class="notranslate">git submodule update --init --recursive --remote
</code></pre>
</li>
</ol>
<h2>四. Redis需要注意的问题</h2>
<ol>
<li>集群环境下使用lua脚本只支持一个key,多个key需要用{}括起来</li>
</ol><hr><p>Thu Feb 17 10:27:30 2022</p><script src="https://utteranc.es/client.js"
repo="caixiangyue/caixiangyue.github.io"
issue-term="pathname"
theme="github-light"
crossorigin="anonymous"
async>
</script>
</body></html>