-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.xml
108 lines (82 loc) · 3.36 KB
/
index.xml
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>七哥的随心谈</title>
<link>http://blog.thinkqs.com/</link>
<description>Recent content on 七哥的随心谈</description>
<generator>Hugo -- gohugo.io</generator>
<language>zh-CN</language>
<copyright>&copy; 2016. All rights reserved.</copyright>
<lastBuildDate>Wed, 07 Sep 2016 13:48:27 +0800</lastBuildDate>
<atom:link href="http://blog.thinkqs.com/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>Golang学习问题1</title>
<link>http://blog.thinkqs.com/post/golang-qa/</link>
<pubDate>Wed, 07 Sep 2016 13:48:27 +0800</pubDate>
<guid>http://blog.thinkqs.com/post/golang-qa/</guid>
<description><p><em>go编译出的程序有系统依赖吗?</em></p>
<pre><code>有,go是编译性语言.
</code></pre>
<p><em>slice内存,引用数组的内存</em></p>
<pre><code>package main
import &quot;fmt&quot;
func main() {
d := []int{1, 2, 3, 4}
e := d[2:]
f := e
fmt.Println(&quot;d1 =&quot;, d)
fmt.Println(&quot;e1 =&quot;, e)
fmt.Println(&quot;f1 =&quot;, f)
e = append(e, 5, 6)
e[1] = 7
fmt.Println(&quot;d2 =&quot;, d)
fmt.Println(&quot;e2 =&quot;, e)
fmt.Println(&quot;f2 =&quot;, f)
}
</code></pre>
<pre><code>e在append前指向d[2:], append后超出cap, 新分配cap*2的内存并copy原数据
d在append前,对e进行操作d会受到影响,append后不再受影响.
f并没有受e的append影响,仍然保留原值.
</code></pre>
<p><em>nil slice和empty slice的append内存扩展机制</em></p>
<pre><code>var slice []int
fmt.Println(&quot;nil len =&quot;, len(slice))
fmt.Println(&quot;nil cap =&quot;, cap(slice))
newSlice := append(slice, 5, 99)
fmt.Println(&quot;newSlice len =&quot;, len(newSlice))
fmt.Println(&quot;newSlice cap =&quot;, cap(newSlice))
newSlice = append(newSlice, 6)
fmt.Println(&quot;newSlice len =&quot;, len(newSlice))
fmt.Println(&quot;newSlice cap =&quot;, cap(newSlice))
newSlice = append(newSlice, 7)
fmt.Println(&quot;newSlice len =&quot;, len(newSlice))
fmt.Println(&quot;newSlice cap =&quot;, cap(newSlice))
</code></pre>
<pre><code>初始len和cap为0
第一次append n个数据后, len和cap为n
之后规则和正常数组相同
</code></pre>
<p><em>不要通过共享来通信,而要通过通信来共享.</em></p>
<p><em>所有进程都阻塞后会报dead lock.</em></p>
<pre><code>package main
import &quot;fmt&quot;
func main() {
c := make(chan int, 1)
c &lt;- 1
c &lt;- 2
fmt.Println(&lt;-c)
fmt.Println(&lt;-c)
}
</code></pre>
</description>
</item>
<item>
<title></title>
<link>http://blog.thinkqs.com/about/</link>
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
<guid>http://blog.thinkqs.com/about/</guid>
<description><p>Nothing.</p>
</description>
</item>
</channel>
</rss>