forked from withlin/advanced-go-programming-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch3-10-func-arg-01.ditaa.txt
50 lines (49 loc) · 3.29 KB
/
ch3-10-func-arg-01.ditaa.txt
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
function arguments and return values layout
+------+-----+-------------------+--------+
| | | | |
| func | Foo | (a bool, b int16) | []byte | unsafe.Sizeof(struct{a bool; b int16; c []byte})
| c1AB | c1AB| cRED | cRED |
+------+-----+-------------------+--------+
| |
+-----------=-+ +-=--------------------------+
| |
v v
+-----------------+-------------------------------+--------------------------------------+
| | | |
| a bool, b int16 | | c reflect.SliceHeader |
| cRED | | cRED |
+-----------------+-=-----------------------------+--------------------------------------+
| | | | |
: : : : :
| | | | |
v v v v v
+---------+----------+----------------------------+-----------------+--------+-----------+
| | | | | | |
| a bool, | b int16, | | c.Data uintptr, | c.Len, | c.Cap int |
| cBLU | cPNK | | cGRE | cGRE | cGRE |
+---------+----------+-=--------------------------+-----------------+--------+-----------+
| | | | |
+---------+ argsize+32(FP)---=-+ | | |
: | | | |
| +-------------------------------------+ <-+ | | |
| | cGRE | | | :
| | c.Cap | | | |
| | 64bit | | | |
| +-------------------------------------+ <-=-|-=------------|---------+
| | cGRE | | | c.Cap+24(FP)
| | c.Len | | |
| | 64bit | | |
| +-------------------------------------+ <-=-|-=------------+c.Len+16(FP)
| | cGRE | |
| | c.Data | |
| | 64bit | |
| +----+----+--------+------------------+ <-=-+c.Data+8(FP)
| |cBLU|cAAA|cPNK |cAAA |
+----> | a | | b | |
|8bit|8bit| 16bit | 32bit |
+----+----+--------+------------------+ <--=-0(FP)
^ ^
| |
| +-=-b+2(FP)
|
+-=-a+0(FP)